リアルタイム版ScrapCalc
code:script.js
scrapbox.on('lines:changed', update);
update(); // 初期化
function update() {
const code = (async () => {${strict()}})();;
//console.log(code);
const sneaky = Function(code);
sneaky();
}
function strict(){
// 一旦リセット
.forEach(span => span.remove());
.map((expr, index) => {
// 全角 [ を半角 [ にする
// 記法がむき出しになっていた場合の処理
if (expr.closest('div.line').classList.contains('cursor-line')) {
text = text.slice(3, -1);
}
// decodeできるときだけdecodeする
try {
text = decodeURI(text);
} catch(e) {
if (!(e instanceof URIError)) throw e;
}
const id = expr.closest('div.line')?.id;
return document.getElementById('${id}')?.insertAdjacentHTML?.(
+ "'beforeend', "
+ \`<span data-id="scrapExec-calculated" style="position:absolute;top:0;right:0;font-style:italic;font-weight:bold;word-wrap:break-word;white-space:break-spaces;max-width:30vw;">
+ "${" + text + "}"
+ "</span>`"
+ ");";
});
return commands.join("\n");
}