yuunkjm-base
ショートカットキーのカスタマイズ
code:script.js
export function setShortcut(aliases, func) {
document.addEventListener('keydown', e => {
//if (e.altKey && !e.ctrlKey && !e.shiftKey) {
if (e.altKey && !e.ctrlKey) {
const supplier = aliasese.code; if (supplier) {
e.preventDefault();
document.getElementById('text-input').focus();
document.execCommand('insertText', null, supplier(e));
}
}
});
}
日付書式
code:script.js
(() => {
const getMonth = t => {
const yyyy = t.getFullYear();
const mm = ("00" + (t.getMonth() + 1)).slice(-2);
return ${yyyy}-${mm};
};
const getDay = t => {
const dd = ("00" + t.getDate()).slice(-2);
return ${dd}
};
const getDayOfWeek = t => {
return wday
};
const getTime = t => {
const hh = ('00' + t.getHours()).slice(-2);
const mm = ('00' + t.getMinutes()).slice(-2);
const ss = ('00' + t.getSeconds()).slice(-2);
return ${[hh, mm, ss].join(':')};
};
scrapbox.TimeStamp.addFormat(() => {
const date = new Date();
return [* [${getMonth(date)}]-${getDay(date)}];
});
scrapbox.TimeStamp.addFormat(() => {
const date = new Date();
return [* [${getMonth(date)}]-${getDay(date)} (${getDayOfWeek(date)})];
});
scrapbox.TimeStamp.addFormat(() => {
const date = new Date();
return ${getMonth(date)}-${getDay(date)};
});
scrapbox.TimeStamp.addFormat(() => {
const date = new Date();
return ${getMonth(date)}-${getDay(date)} (${getDayOfWeek(date)});
});
})();
code:script.jssss
scrapbox.TimeStamp.addFormat('*] [[]YYYY-MM[-DD[]]')
scrapbox.TimeStamp.addFormat('*>] [[]YYYY-MM[-DD[]]')
scrapbox.TimeStamp.addFormat('YYYY-MM-DD')
/icons/hr.icon
見える文字数カウンター
/icons/hr.icon
メニュー
/icons/hr.icon
栞ブックマークメニュー
code:script.js
const __bkmClass = '.deco-\\.' /* ここで記法のセレクタを設定してね。デフォルトはドットです */
const __bkmMenuTitle = 'Bookmarks'
scrapbox.PageMenu.addMenu({ title: __bkmMenuTitle, image: 'dummy.png',
onClick: function() {
const __fixedHeaderHeight = ($('.navbar').css('position') == 'fixed' ? $('.navbar').height() : 0) +
($('.navbar-pagemenu').height() || 0)
scrapbox.PageMenu(__bkmMenuTitle).removeAllItems()
$(__bkmClass).closest('.line').each(function(i, e){
scrapbox.PageMenu(__bkmMenuTitle).addItem({
title: $(e).find(__bkmClass).text(),
onClick: function() {
$('html,body').animate({
scrollTop: $(e).offset().top - $('body').offset().top - __fixedHeaderHeight
}, 150)
}
})
})
}
})
/icons/hr.icon
トップに飛ぶメニュー
code:script.js
scrapbox.PageMenu.addMenu(
{title:"Top",
onClick:function(){location="./"}
})
/icons/hr.icon
Gyazoに飛ぶメニュー
code:script.jssss
scrapbox.PageMenu.addMenu(
{title:"Gyazo",
})
/icons/hr.icon
ピン止めされたページメニュー
code:script.js
const menuTitle = 'Pinned'
scrapbox.PageMenu.addMenu({
title: menuTitle,
onClick: () => {
scrapbox.PageMenu(menuTitle).removeAllItems()
scrapbox.PageMenu(menuTitle).addItem({
title: "top",
onClick: e => { e.currentTarget.setAttribute("href", "./") }
})
fetch(/api/pages/${scrapbox.Project.name}, { credentials: "include" })
.then(res => res.json())
.then(data => {
const pinnedPages = Array.from(data.pages).filter(page => 0 < page.pin)
pinnedPages.forEach(page => {
scrapbox.PageMenu(menuTitle).addItem({
title: page.title,
onClick: e => { e.currentTarget.setAttribute("href", ./${page.title}) }
})
})
})
}
})
/icons/hr.icon
ボタン
空白ボタン
code:script.js
scrapbox.PopupMenu.addButton({
title: '字下げ',
onClick: text => text.split(/\n/).map(line => [ ]${line}).join('\n')
})
CodeBlockボタン
code:script.js
scrapbox.PopupMenu.addButton({
title: 'CodeBlock',
onClick: text => "code:\n"+text.split(/\n/).map(line => "\t"+line.replaceAll(/\t/g," ")).join('\n')
})
codeボタン
code:script.js
scrapbox.PopupMenu.addButton({
title: 'Code',
onClick: text => \`${text}\`
})
空白削除ボタン
code:script.js
scrapbox.PopupMenu.addButton({
title: '空行削除',
onClick: text => text.split(/\n/).filter(line => !line.match(/^\s*$/)).join('\n')
})
/icons/hr.icon
数式
code:script.js
scrapbox.PopupMenu.addButton({
title: '数式',
onClick: text => [\$ ${text}]
})
マーカーボタン
code:script.js
scrapbox.PopupMenu.addButton({
title: '下線',
onClick: text => [[${text}]]
})
/icons/hr.icon
選択範囲に引用符をつけるボタン
code:script.js
scrapbox.PopupMenu.addButton({
title: '引用',
onClick: text => text.split(/\n/).map(line => >${line}).join('\n')
})
/icons/hr.icon
箇条書きナンバリングボタン
code:script.js
scrapbox.PopupMenu.addButton({
title: 'No.',
onClick: text => text.split(/\n/).map((line, index) => ${index+1}. ${line}).join('\n')
})
/icons/hr.icon
選択文字列をプロジェクト内で検索ポップアップボタン
code:script.jssssss
// 選択された文字列をScrapboxプロジェクト内で検索する
scrapbox.PopupMenu.addButton({
title: '検索',
onClick: function (text) {
}
});
/icons/hr.icon
空白削除
code:script.js
scrapbox.PopupMenu.addButton({
title: '空削',
onClick: text => text.split('\n').map(function(line) {
return line.replaceAll(' ', '')
}).join('\n')
})
エスケープ
[]をエスケープする
code:script.js
scrapbox.PopupMenu.addButton({
title: '[]Esc',
onClick: text => text.split('\n').map(function(line) {
return line.replaceAll(' ', '')
}).join('\n')
})
/icons/hr.icon
フォーマットボタン
1. 行頭の空白を空白1つあたりTab1つに置き換える
3. 文字化けを修正する ( での を での に直す)
4. 全角英数字を半角英数字に置き換える
5. 全角括弧を半角括弧に置き換える
6. 括弧で囲まれた前後が空白でなければ空白を1つ入れる
7. コードブロック記法の前後が空白でなければ空白を1つ入れる
code:script.js
scrapbox.PopupMenu.addButton({
title: 'Format',
onClick: text => text.split('\n').map(function(line) {
return line
.replaceAll(/^\s+/g, s => s.replace(/\s/g, '\t'))
.replaceAll(/ぁ-ん|ァ-ヴ゙/g, s => String.fromCharCode(s.charCodeAt(0) + 1)) .replaceAll(/A-Za-z0-9/g, s => String.fromCharCode(s.charCodeAt(0) - 0xFEE0)) .replaceAll(/、/g, ',')
.replaceAll(/。/g, '.')
.replaceAll(/(/g, ' (')
.replaceAll(/)/g, ') ')
.replaceAll(///g, '/')
.replaceAll(/\S\(/g, s => s.charAt(0) + ()
.replaceAll(/\)\S/g, s => ') ' + s.charAt(1))
.replaceAll(/\S.*/g, s => s.charAt(0) + ' ' + s.slice(1))
.replaceAll(/.*\S/g, s => s.slice(0, -1) + ' ' + s.slice(-1))
.replaceAll(/(\S)(\s+)/g, '$1 ')
}).join('\n')
})
/icons/hr.icon
ソートボタン
code:script.js
scrapbox.PopupMenu.addButton({
title: 'Sort',
onClick: text => {
const re = /^(\s*)/
const b = re.exec(text)1.length const lines = text.split(/\n/)
let sorting = [], chLines = []
for (var i = 0; i < lines.length; i++) {
if (0 < chLines.length) chLines.unshift('')
sorting.push(line + chLines.join('@n@'))
chLines = []
}
return sorting.sort().join('\n').replace(/@n@/g, '\n')
}
})
/icons/hr.icon
文字カウントポップアップボタン
code:script.jssssss
scrapbox.PopupMenu.addButton({
title: function (text) {
const chars = text.replace(/\r\n/g, '').length const words = text.trim().split(/\r\n\s+/).length return ${chars}c ${words}w
},
onClick: () => null
})
Markdown to scrapbox
code:script.js
scrapbox.PopupMenu.addButton({
title: 'md=>sc', //"MdSc" is the name of popup button.
onClick: text =>{
////リスト////
//リストのマーカーが行頭にある場合
text=text.split(/\n/).map(line => line.replace(/^\*\-\+ /g,' ')).join('\n') //行頭以外にあるリストのマーカー(*, -, +)を消す
text=text.split(/\n/).map(line => line.replace(/\*\-\+ /g,'')).join('\n') //リストのインデントが半角スペース2個ずつの場合
//text=text.split(/\n/).map(line => line.replace(/ {2}/g,' ')).join('\n')
//リストのインデントが半角スペース4個ずつの場合
text=text.split(/\n/).map(line => line.replace(/ {4}/g,' ')).join('\n')
////数字付きリスト
text=text.split(/\n/).map(line => line.replace(/^(0-9+\. )/g,' $1')).join('\n') ////強調////
//太字
text=text.split(/\n/).map(line => line.replace(/\*{2}(^*+)\*{2}/g,'$1')).join('\n') text=text.split(/\n/).map(line => line.replace(/\_{2}(^_+)\_{2}/g,'$1')).join('\n') //イタリック
text=text.split(/\n/).map(line => line.replace(/\_(^_+)\_/g,'$1')).join('\n') ////取り消し線////
text=text.split(/\n/).map(line => line.replace(/\~\~(\~+|^~+)\~\~/g,'$1')).join('\n') ////Header level 1-6////
//Header level 1
text=text.split(/\n/).map(line => line.replace(/^# (.*)/g,'$1')).join('\n')
//Header level 2
text=text.split(/\n/).map(line => line.replace(/^#{2} (.*)/g,'$1')).join('\n')
//Header level 3
text=text.split(/\n/).map(line => line.replace(/^#{3} (.*)/g,'$1')).join('\n')
//Header level 4
text=text.split(/\n/).map(line => line.replace(/^#{4} (.*)/g,'$1')).join('\n')
//Header level 5
text=text.split(/\n/).map(line => line.replace(/^#{5} (.*)/g,'$1')).join('\n')
//Header level 6
text=text.split(/\n/).map(line => line.replace(/^#{6} (.*)/g,'$1')).join('\n')
////リンクと画像////
//Hyperlink without linktext / Image without alt text
//Image with alt text
//Hyperlink with linktext
//URL with angle brackets
////水平線////
text=text.split(/\n/).map(line => line.replace(/^(\*|\-|\_){3,}/g,'/icons/hr.icon')).join('\n') ////エスケープを元に戻す////
text=text.split(/\n/).map(line => line.replace(/\\([\\|`|\*|_|\{|\}|\|\|\(|\)|#|\+|\-|\.|\!])/g,'$1')).join('\n') return text;
}
})
/icons/hr.icon
曜日挿入
2021-10-05
2021-10-06
code:script.js
const getDay = t => {
const dd = ("00" + t.getDate()).slice(-2);
return ${dd}
};
const getDayOfWeek = t => {
return wday
};
const getDateWithDay = text => {
if (!text||text.indexOf("\n")!=-1) {
return "_";
}
console.log(found);
if(!found) {return "_";}
return found + " (" +getDayOfWeek(date)+")";
};
scrapbox.PopupMenu.addButton({
title: text => getDateWithDay(text),
onClick: text => {
if (!text) {return "_";}
const lines = text.split("\n");
const reps = lines.map(t => {
if(!found) {return t}
return text.replace(found, found + " (" +getDayOfWeek(date)+")");
});
return reps.join("\n");
}
})
/icons/hr.icon
複数行計算
code:script.js
scrapbox.PopupMenu.addButton({
title: text =>{
if(!text||text.indexOf("\n")==-1) {return "_";}
if(!found) {return "_";}
const nums = found.map(x => Number(x.replaceAll("_","").replaceAll(",","")));
const sum = Math.round(nums.reduce((p,c)=>{return p+c})*10000)/10000;
return nums.join("+") + " = "+ sum;
},
onClick: () => null
})
範囲計算
code:script.js
const calcText = text => {
if (!text||text.indexOf("\n")!=-1) {return "_";}
if (!f1 || f10 == '') {return "_";} if (!found || found0 == '') {return "_";} try {
const roundThreshold=10000;
const formula = found0.replaceAll(",",""); return found0 + "=" + Math.round(new Function("return "+formula)()*roundThreshold)/roundThreshold; } catch (error) {
// console.error(error);
return "err";
}
};
scrapbox.PopupMenu.addButton({
title: text => calcText(text),
onClick: text => calcText(text)
});
/icons/hr.icon