generated at
UserScript:アイコンボタン2
タイトルは変更予定
eval() 非推奨なので動的import使用する
アイコンボタン
ページのサフィックスとして、-button が必要
スクリプト
スクリプト名は、icon-button.js 固定
button2.js内でexecuteという関数をexportして下さい
script2.js
const buttonFileName = 'button2.js'; document.getElementById('editor').addEventListener('click', e => { const t = e.target; if (!(t.tagName === 'IMG' && t.classList.contains('icon') && t.title.endsWith('-button')))return; e.preventDefault(); e.stopImmediatePropagation(); const title = encodeURIComponent(t.title); //console.log(`Start loading the script from /api/code/${scrapbox.Project.name}/${title}/${buttonFileName}`); import(`/api/code/${scrapbox.Project.name}/${title}/${buttonFileName}`) .then(({execute}) => { //console.log('Succeeded in loading the script.'); execute(); }) .catch(error => console.error(error)); });

icon-button.js 内で execute という関数を export して下さい
script.js
const buttonFileName = 'icon-button.js'; document.getElementById('editor').addEventListener('click', e => { const t = e.target; if (!(t.tagName === 'IMG' && t.classList.contains('icon') && t.title.endsWith('-button')))return; e.preventDefault(); e.stopImmediatePropagation(); const title = encodeURIComponent(t.title); //console.log(`Start loading the script from /api/code/${scrapbox.Project.name}/${title}/${buttonFileName}`); import(`/api/code/${scrapbox.Project.name}/${title}/${buttonFileName}`) .then(({execute}) => { //console.log('Succeeded in loading the script.'); execute(); }) .catch(error => console.error(error)); });


UserScript