minaminao
https://gyazo.com/445ad3ce538f1832f991eebd0d8ad00f
nrryuya.icon > チキンライスはもう飽きた
yudetamago.icon > アイコン癒やされる
tomoaki.icon > アパホテル在住
PopupMenu
code:script.js
scrapbox.PopupMenu.addButton({
title: 'Code',
onClick: text => '' + text + ''
});
scrapbox.PopupMenu.addButton({
title: '$ Math',
onClick: text => '$ ' + text.replace(/^\s*\{\\displaystyle\s?(.+)\}\s*$/, "$1") + ''
});
scrapbox.PopupMenu.addButton({
title: '空白除去',
onClick: text => text.replace(/ /g, '')
});
scrapbox.PopupMenu.addButton({
title: '小文字',
onClick: text => text.toLowerCase()
});
scrapbox.PopupMenu.addButton({
title: '>',
onClick: text => text.replace(/\.+?\/g,"").replace(/。/g,"。\n").replace(/^/g,">").replace(/\r\n+/g,"\n>").replace(/>\s+/g,">").replace(/\n>$/,"").replace(/^>+/g,">") });
scrapbox.PopupMenu.addButton({
title: 'TeX',
onClick: text => text.replace(/\[\$ (^\]*)\]/g,"$$ $1 $$") });
目次をつける
code:script.js
const set_menu = () => {
scrapbox.PageMenu('title_menu').removeAllItems();
let section_titles = document.querySelectorAll(".section-title");
section_titles.forEach((e) => {
scrapbox.PageMenu('title_menu').addItem({
title: e.innerText,
onClick: () => { scrollTo(0, e.offsetTop); }
})
});
};
scrapbox.PageMenu.addMenu({
title: 'title_menu',
onClick: set_menu
})
set_menu();
トグルと目次をデフォルトで開く
code:script.js
const open_index = () => {
let toggle = document.querySelector(".toggle-button.closed");
if (toggle) toggle.click();
let title_menu = document.getElementById("title_menu");
if (title_menu) {
set_menu();
title_menu.click();
}
}
open_index();
let prev_href = location.href;
const observer = new MutationObserver(records => {
if (prev_href !== location.href) {
setTimeout(open_index, 500);
prev_href = location.href;
}
});
const options = {
childList: true,
subtree: true
};
observer.observe(document.querySelector("title"), options);
ソート
code:script.js
scrapbox.PopupMenu.addButton({
title: 'sort',
onClick: text => {
text = text.replace(/\t/g, " ");
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')
}
})