import
使い方
各projectの自分のページの script.js
に以下を貼り付ける
jsimport "../../takker/import/script.js";
2022-02-04 09:28:09 #editor
がmountされる前に script.js
が読み込まれるようになってしまった
応急処置として以下のコードを導入する
script.jsawait new Promise(resolve => {
let timer = null;
timer = setInterval(() => {
if (!document.getElementById('editor')) return;
clearInterval(timer);
resolve();
}, 1000);
});
script.jsconst name = "Scrapbox-UserScript-Switcher";
const devUserPage = "import-dev";
const params = new URLSearchParams(location.search);
script.jsif (params.has("noscript")) {
console.info(`[${name}] No script mode`);
script.js} else if(params.has("dev")) {
console.info(`[${name}] Development mode. Loading "${
`../${devUserPage}/script.js`
}" instead...`);
await import(`../${devUserPage}/script.js`);
console.info(`[${name}] Successfully loaded.`);
script.js} else {
// 通常のUserScriptを読み込む
await importProductionUserScript();
}
projectごとにUserScriptを切り替える
script.jsasync function importProductionUserScript() {
const defaultSrc = "../../takker-dist/for-any-project-min/script.js";
switch(scrapbox.Project.name) {
case "takker":
await Promise.all([
await import(defaultSrc),
await import("./takker.js"),
]);
break;
case "takker-memex":
await import("../../takker-dist/for-any-project-min/takker-memex.js");
break;
case "villagepump":
await Promise.all([
await import(defaultSrc),
await import("./villagepump.js"),
]);
break;
case "programming-notes":
await Promise.all([
await import(defaultSrc),
await import("./programming-notes.js"),
]);
break;
script.js case "takker-books": {
const {
addButton,
insertText,
} = await import(defaultSrc);
addButton({
display: ({ selection }) => selection.hasSelection() ?
"\\n" : "",
onClick: async ({ selection }) => {
const text = selection.getSelectedText();
await insertText(
text.replaceAll("\n", "")
.replaceAll(".", ".\n")
.replaceAll(".", ".\n")
.replaceAll("。", "。\n")
);
},
});
addButton({
display: ({ selection }) =>
/https:\/\/gyazo\.com\/[a-z0-9]+/.test(
selection.getSelectedText()
) ? { type: "trim" } : "",
onClick: ({ selection }) => {
const id = selection
.getSelectedText()
.match(
/https:\/\/gyazo\.com\/([a-z0-9]+)/
)?.[1];
if (!id) return;
window.open(`https://gyazo.com/${id}/transform`);
},
});
await import("../cosense-srsの穴埋めを作るPopupMenu/script.js");
break;
}
script.js default:
await import(defaultSrc);
break;
}
}
個別のproject用scripts
villagepump.jsimport { execute } from "../Scrapbox-theme-saver/script.js";
execute({interval: 30 * 60 * 1000});
import "../pin-diary-6-min/script.js";
import "../18:00~09:00は井戸端を開けなくするUserScript/ban.js";
import { setup } from "../ToMyProj/mod.js";
setup("takker");
themeを paper-dark-dark
に変更する
programming-notes.jsimport { setTheme } from "../scrapbox-theme-customizer/script.js";
setTheme("paper-dark-dark");
takker.jsimport "../scrapbox-open-episopass/script.js";
takker-memex.jsimport "../for-any-project/script.ts";
export * from "../for-any-project/script.ts";
import "../New_Buttonで開くページを変更する/script.js";
import "../LETUS_online_editor形式に変換してcopyするPopupMenu/script.js";
import "../選択範囲をspell_checkするPopupMenu/script.js";
import "../文字カウント_(scrapbox)/script.js";
import "../takker99%2Ftakker-scheduler%2Fmobile/script.ts";
import "../scrapbox-open-episopass/script.js";
takker-memex.jsimport { main } from "../takker99%2Ftakker-scheduler/auto-diary.ts";
main();
takker-memex(txt)for-takker-memex
[/takker-memex]で使うUserScript
[https://scrapbox.io/api/code/takker/import/takker-memex.js takker-memex.js]を[このURL @URL@]でbundleしたもの
code:script.js
@CODE@
UserCSS
UserCSSも script.js
から読み込ませるようにしようかな
projectごとにUserCSSを動的に切り替えることができる
全く見ない