UserScript:アイコンボタン2
タイトルは変更予定
アイコンボタン
スクリプト
スクリプト名は、icon-button.js 固定
button2.js内でexecuteという関数をexportして下さい
script2.jsconst 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.jsconst 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));
});