TamperMonkeyでUserScript一式を未参加のprojectでも使う
bsahd.icon
.user.jsにするとインストールしやすい
code:script.user.js
// ==UserScript==
// @name TamperMonkeyでUserScript一式を未参加のprojectでも使う
// @version 0.5
// @description TamperMonkeyでUserScript一式を未参加のprojectでも使う
// @author bsahd and takker
// @license MIT
// @copyright Copyright (C) 2025 bsahd and takker; This software is a modified version of the original software licensed under the MIT License. Original Copyright (c) 2021 takker.
// ==/UserScript==
/*
改変部分
読み込み方法: dynamic importからDOMによるscriptタグの挿入に変更
グローバル変数scrapboxへのアクセス方法: unsafeWindowを使用しないと本体ドキュメントのグローバルにアクセスできないようになったので修正
インターバル間隔: 1000msから100msに変更し、ページ読み込み後すぐスクリプトを読み込めるようにした
雑に1000ms待つ場所を消した
*/
window.addEventListener("load", async () => {
await new Promise(resolve => {
let timer = null;
timer = setInterval(() => {
if (!document.getElementById('editor')) return;
clearInterval(timer);
resolve();
}, 100);
});
const { projects } = await res.json();
if (projects.map(({ name }) => name).includes(unsafeWindow.scrapbox.Project.name)) {
console.info(You belong to "/${unsafeWindow.scrapbox.Project.name}".);
return;
}
console.info(You don't belong to "/${unsafeWindow.scrapbox.Project.name}". Loading Userscripts via TamperMonkey...);
const script = document.createElement("script");
script.type = "module";
script.async = true;
script.crossorigin="use-credentials";
script.src = ""; // UserScriptの読み込み元
document.head.appendChild(script)
}, { once: true });