選択した文字をデライトに転送するUserScript
code:script.js
scrapbox.PopupMenu.addButton({
title: デライトに送る,
onClick: text => {
let title = text.split('\n')0; title = encodeURIComponent(window.prompt(知名を入力してください(空白可), title));
// titleがない場合は空文字に設定
if (!title) title = "";
// Scrapbox → デライト形式への変換
text = text
.split('\n')
.map(line => {
// 強調リンク hoge → **hoge**
line = line.replace(/\[\* (^\]+)\]/g, '**$1**'); line = line.replace(/\[(^\\*]^\]*)\]/g, '{$1}'); // タブ→スペース4個に仮変換(正規化)
line = line.replace(/^\t+/, match => ' '.repeat(match.length * 4));
// 文頭のスペースの数をカウントして、箇条書きに変換
const spaceMatch = line.match(/^ +/);
if (spaceMatch) {
const spaces = spaceMatch0.length; const indentLevel = Math.floor(spaces / 1); // 1スペースごとに1段下げる
line = ' '.repeat(indentLevel) + '- ' + line.trimStart();
}
return line;
})
.join('\n');
text = encodeURIComponent(text);
const url = https://dlt.kitetu.com/?kw=${title}&dln=${text}#drw;
window.open(url);
return null;
}
});