import
使い方
各projectの自分のページのscript.jsに以下を貼り付ける
code:js
import "../../takker/import/script.js";
2022-02-04 09:28:09 #editorがmountされる前にscript.jsが読み込まれるようになってしまった
応急処置として以下のコードを導入する
code:script.js
await new Promise(resolve => {
let timer = null;
timer = setInterval(() => {
if (!document.getElementById('editor')) return;
clearInterval(timer);
resolve();
}, 1000);
});
code:script.js
const name = "Scrapbox-UserScript-Switcher";
const devUserPage = "import-dev";
const params = new URLSearchParams(location.search);
code:script.js
if (params.has("noscript")) {
console.info([${name}] No script mode);
code: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.);
code:script.js
} else {
// 通常のUserScriptを読み込む
await importProductionUserScript();
}
projectごとにUserScriptを切り替える
code:script.js
async 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;
code: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+)/ if (!id) return;
window.open(https://gyazo.com/${id}/transform);
},
});
await import("../cosense-srsの穴埋めを作るPopupMenu/script.js");
break;
}
code:script.js
default:
await import(defaultSrc);
break;
}
}
個別のproject用scripts
code:villagepump.js
import { 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に変更する
code:programming-notes.js
import { setTheme } from "../scrapbox-theme-customizer/script.js";
setTheme("paper-dark-dark");
code:takker.js
import "../scrapbox-open-episopass/script.js";
code:takker-memex.js
import "../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";
code:takker-memex.js
import { main } from "../takker99%2Ftakker-scheduler/auto-diary.ts";
main();
code:takker-memex(txt)
for-takker-memex
code:script.js
@CODE@
/icons/hr.icon
UserCSS
code:style.css
@import "../import-css/style.css";
code:default.css
@import "../import-css/default.css";
UserCSSもscript.jsから読み込ませるようにしようかな
projectごとにUserCSSを動的に切り替えることができる
全く見ない