UserScript:テキストの加工
code:icon_snipet.js
import "../tools/script.js"
const iconSnipet = text => {
return(text.mapLine(line => line. sandwich("".icon")));
};
scrapbox.PopupMenu.addButton({
title: " 🙂 ",
onClick: iconSnipet
});
code:icon_link_exchange_snipet.js
import "../tools/script.js"
const iconLinkExchangeSnipet = text => {
let foundIcon = text. match(RegExp("\\.icon]","g"));
let func1 = line => line. replace(RegExp("\\.icon]","g"),"]");
let func2 = line => line. replace(RegExp("]","g"),".icon]");
if (foundIcon) {
return(text.mapLine(func1));
} else {
return(text.mapLine(func2));
}
};
scrapbox.PopupMenu.addButton({
title: " 😀⇔[] ",
onClick: iconLinkExchangeSnipet
});
よく使う数学記号
code:math_sig_snipet.js
import "../tools/script.js"
const mathSigSnipet = text => {
let func = line => line.
replace(RegExp(" x ","g"), " × ").
replace(RegExp(" -> ","g"), " → ");
return(text.mapLine(func));
};
scrapbox.PopupMenu.addButton({
title: " × ",
onClick: mathSigSnipet
});
全角文字を半角に変換する
code:zen_to_han.js
import "../tools/script.js"
const zenToHanSnipet = text => {
let func = line => line.
replace(RegExp("(.,:;)","g"), "$1 "). replace(RegExp("\uFF01-\uFF5D","g"), s => String.fromCharCode(s.charCodeAt(0)-0xFEE0)); return(text.mapLine(func));
};
scrapbox.PopupMenu.addButton({
title: " A>A ",
onClick: zenToHanSnipet
});