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