●PageMenu:リンク先ページのコードを取得して追記する(table)
挙動
table記法で取得対象を書いておくとそれに従ってコードを取得してページ内に追加する
tableの書き方例
table:AddCodes
tableタイトル:AddCodes(このページではAddCodes.csvと表示されていますが.csvは不要です)
1列目:コードブロックのタイトル
2列目:ページリンク
※見出し行をつけても構いません(2列目がページリンクでなければスキップします)
※3列目以降に何か書いても構いません
注意
自分用なので動作の保証はしません
リンク先のページタイトルに(プロジェクト名を示す以外の)「/」が入っているとうまくいきません
code:script.js
(()=>{
scrapbox.PageMenu.addMenu({
title: 'AddCodes',
});
scrapbox.PageMenu('AddCodes').addItem({
title: 'AddCodes.csv',
onClick: () => {addCodesTable()},
})
function addCodesTable(){
fetch(/api/table/${scrapbox.Project.name}/${scrapbox.Page.title}/AddCodes.csv)
.then(response => response.text())
.then(text => {
if(!text) return;
text.split('\n').forEach(line=>{
if(!line||!line.split(',')1||!line.split(',')1.match(/^\.*\$/)) return; const type = line.split(',')0; const url = target.includes('/') ? /api/code/${target}/${type} :
/api/code/${scrapbox.Project.name}/${target}/${type};
fetch(url)
.then(response => response.text())
.then(text => {
if(!text) return;
const str = code:${type}\n\t + text.replace(/\n/g,'\n\t');
const write = window.open(https://scrapbox.io/${scrapbox.Project.name}/${scrapbox.Page.title}?body=${encodeURIComponent(str)});
setTimeout(()=>write.close(),30000);
});
})
});
}
})();