ScrapboxUserScripts
import用
Ctrl+Tのタイムスタンプ表記を固定
code:set-ctrl-t-format.js
scrapbox.TimeStamp.removeAllFormats()
scrapbox.TimeStamp.addFormat("YYYY-MM-DD")
scrapbox.TimeStamp.addFormat("YYYY-MM-DD HH:mm:ss")
scrapbox.TimeStamp.addFormat("YYYY-MM")
code:tweet-card-helper.js
const tweetURLRegex = /twitter.com\/(.+)\/status\/(\d+)/
scrapbox.PopupMenu.addButton({
title: text => tweetURLRegex.test(text) ? "tweet-card" : null,
onClick: (text) => {
const m = text.match(tweetURLRegex);
if (!m) return text;
return [https://tweet-card.now.sh/${m[2]}.jpg?lang=ja https://twitter.com/${m[1]}/status/${m[2]}] https://twitter.com/${m[1]}/status/${m[2]};
},
});
ci7lus.icon にこれパクっていいか聞いたところ、えよーんとのことでした
code:diary-template.js
if (!window.dayjs) {
const dayJsMinJs = document.createElement("script");
dayJsMinJs.src =
document.body.appendChild(dayJsMinJs);
}
scrapbox.PageMenu.addMenu({
title: DailyReport,
onClick: () => {
if (!scrapbox.Page.lines || !scrapbox.Page.lines.length == 1) return;
const input = prompt("日報テンプレートを展開したい日付を相対(\d+)または絶対(2020-1-1)で(入力なしで今日)");
if (input === null) return
const diff = parseInt(input.trim() || 0);
const abs = input.split("-").length === 3 && dayjs(input);
if ((Number.isNaN(diff) && !abs) || (abs && !abs.isValid())) return;
const today = abs ? abs.startOf("days") : dayjs().startOf("days").add(diff, "days");
const yesterday = today.clone().subtract(1, "days");
const tomorrow = today.clone().add(1, "days");
console.log(today.format(), yesterday.format(), tomorrow.format());
const conf = confirm(対象の日付は ${today.format("YYYY.M.D")} ですか?);
if (!conf) return;
const line = document.getElementById("L" + scrapbox.Page.lines0.id); mimicClick(line.id, line.offsetWidth, lastChar.offsetTop + 10);
const textarea = document.getElementById("text-input");
const diaryDateFormat = "YYYY-MM-DD"
textarea.value = [
日記:${today.format(diaryDateFormat)}\n,
<- [日記:${tomorrow.format(diaryDateFormat)}] / ,
#日記:${tomorrow.format("YYYY/MM")} / ,
[日記:${yesterday.format(diaryDateFormat)}] ->\n
].join("");
const event = document.createEvent("Event");
event.initEvent("input", true, true);
textarea.dispatchEvent(event);
mimicClick(line.id, line.offsetWidth, lastChar.offsetTop + 10);
},
});
const mimicClick = (targetId, left, top) => {
const genEvent = (type) => {
const event = document.createEvent("MouseEvents");
event.initMouseEvent(
type,
true,
true,
window,
1,
0,
0,
left,
top,
false,
false,
false,
false,
0,
null
);
return event;
};
const elm = document.getElementById(targetId);
elm.dispatchEvent(genEvent("mousedown"));
elm.dispatchEvent(genEvent("mouseup"));
elm.dispatchEvent(genEvent("click"));
};
選択した箇所をcodeにする
code:wrap-code.js
scrapbox.PopupMenu.addButton({
title: 'code',
onClick: text => \`${text}\`
})