UserScripts
code:script.js
日記テンプレート
code:diary-template.js
/* MIT License Copyright (c) 2020 ci7lus */
import { importExternalJs } from "/api/code/ci7lus/userscript-utils/import-external-js.js";
importExternalJs(
);
import { insertText } from "/api/code/customize/scrapbox-insert-text/script.js";
scrapbox.PageMenu.addMenu({
title: 日記,
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_MM/DD")} ですか?);
if (!conf) return;
insertText({
text: ${today.format("YYYY_MM/DD")}\n<- [${tomorrow.format("YYYY_MM/DD")}] / [${today.format("YYYY_MM")}] / [${yesterday.format("YYYY_MM/DD")}] ->\n\n\n\n<- [${tomorrow.format("YYYY_MM/DD")}] / [${today.format("YYYY_MM")}] / [${yesterday.format("YYYY_MM/DD")}] ->,
});
},
});
code:quote.js
scrapbox.PopupMenu.addButton({
title: 'quote',
onClick: text => text.split(/\n/).map(line => > ${line}).join('\n')
})
code:caption.js
scrapbox.PopupMenu.addButton({
title: 'caption',
onClick: text => {
return text.split(/\n/).map(line => |${line}).join('\n');
}
});
code:alias.js
scrapbox.PopupMenu.addButton({
title: 'alias',
onClick: text => text.split(/\n/).map(line => ^${line}).join('\n')
})
code:a.js
scrapbox.PopupMenu.addButton({
title: 'Gyazo Raw',
onClick: (text) => {
const gyazoRegex = /(https:\/\/gyazo\.com\/a-f0-9{32})/g; if (text.endsWith('/raw.png') || text.endsWith('/raw.png]')) {
return text;
}
const newText = text.replace(gyazoRegex, '$1/raw.png');
return newText;
}
});
code:alias-link.js
// scrapbox-alias-link/script.js
(function () {
"use strict";
/*── スタイル注入 ──*/
const style = document.createElement("style");
style.textContent = `
position: fixed;
inset: 0;
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
}
padding: 0;
width: 280px;
display: flex;
flex-direction: column;
font-size: 13px;
font-family: 'Inter', 'Noto Sans JP', sans-serif;
font-weight: 400;
letter-spacing: .03em;
}
font-size: 11px;
padding: 10px 14px 6px;
text-transform: uppercase;
letter-spacing: .05em;
}
padding: 10px 14px;
}
width: 100%;
box-sizing: border-box;
background: transparent;
border: none;
padding: 4px 0;
font-size: 13px;
font-family: 'Inter', 'Noto Sans JP', sans-serif;
outline: none;
letter-spacing: .03em;
}
list-style: none;
margin: 0;
padding: 4px 0;
max-height: 200px;
overflow-y: auto;
min-height: 32px;
}
padding: 7px 14px;
cursor: pointer;
font-size: 13px;
display: flex;
align-items: center;
gap: 8px;
}
}
padding: 7px 14px;
font-size: 11px;
}
font-size: 11px;
padding: 8px 14px;
display: flex;
justify-content: space-between;
}
`;
document.head.appendChild(style);
/*── PopupMenuに登録 ──*/
scrapbox.PopupMenu.addButton({
title: "#エイリアス",
onClick: (selectedText) => {
return new Promise((resolve, reject) => {
const project = scrapbox.Project.name;
/*── DOM構築 ──*/
const overlay = document.createElement("div");
overlay.id = "alias-overlay";
overlay.innerHTML = `
<div id="alias-dialog">
<div id="alias-header">リンク先ページを選択</div>
<div id="alias-input-wrap">
<input id="alias-input" type="text"
placeholder="ページ名を入力..."
autocomplete="off" />
</div>
<ul id="alias-suggestions">
<li class="alias-empty">文字を入力して検索</li>
</ul>
<div id="alias-footer">
<span>↑↓ 選択 / Enter 確定</span>
<span>Esc キャンセル</span>
</div>
</div>
`;
document.body.appendChild(overlay);
const input = overlay.querySelector("#alias-input");
const list = overlay.querySelector("#alias-suggestions");
let activeIndex = -1;
let debounceTimer;
input.focus();
/*── 検索 ──*/
const search = async (query) => {
list.innerHTML = "";
activeIndex = -1;
if (!query.trim()) {
list.innerHTML = <li class="alias-empty">文字を入力して検索</li>;
return;
}
try {
const res = await fetch(/api/pages/${project}/search/query?q=${encodeURIComponent(query)});
const data = await res.json();
const pages = data.pages.slice(0, 8);
if (pages.length === 0) {
list.innerHTML = <li class="alias-empty">該当なし — Enterで「${query}」を直接指定</li>;
return;
}
pages.forEach((page) => {
const li = document.createElement("li");
li.className = "alias-item";
li.textContent = page.title;
li.addEventListener("mousedown", (e) => {
e.preventDefault();
confirm(page.title);
});
list.appendChild(li);
});
} catch {
list.innerHTML = <li class="alias-empty">検索に失敗しました</li>;
}
};
input.addEventListener("input", () => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => search(input.value), 150);
});
/*── キーボード ──*/
input.addEventListener("keydown", (e) => {
const items = list.querySelectorAll(".alias-item");
if (e.key === "ArrowDown") {
e.preventDefault();
activeIndex = Math.min(activeIndex + 1, items.length - 1);
items.forEach((el, i) => el.classList.toggle("active", i === activeIndex));
} else if (e.key === "ArrowUp") {
e.preventDefault();
activeIndex = Math.max(activeIndex - 1, -1);
items.forEach((el, i) => el.classList.toggle("active", i === activeIndex));
} else if (e.key === "Enter") {
e.preventDefault();
const target =
activeIndex >= 0
: input.value.trim();
if (target) confirm(target);
} else if (e.key === "Escape") {
e.preventDefault();
cleanup();
reject();
}
});
overlay.addEventListener("click", (e) => {
if (e.target === overlay) { cleanup(); reject(); }
});
/*── 確定・後処理 ──*/
const cleanup = () => overlay.remove();
const confirm = (target) => {
cleanup();
resolve([# ${selectedText}[${target}]]);
};
});
},
});
})();
code:alias-search.js
// scrapbox-quick-link/script.js
import { insertText } from "/api/code/customize/scrapbox-insert-text/script.js";
(function () {
"use strict";
/*── スタイル注入 ──*/
const style = document.createElement("style");
style.textContent = `
position: fixed;
inset: 0;
z-index: 9999;
background: rgba(0, 0, 0, 0.3);
display: flex;
align-items: flex-start;
justify-content: center;
padding-top: 120px;
}
width: 360px;
display: flex;
flex-direction: column;
font-size: 13px;
font-family: 'Inter', 'Noto Sans JP', sans-serif;
font-weight: 400;
letter-spacing: .03em;
box-shadow: 0 4px 24px rgba(0,0,0,0.12);
}
display: flex;
align-items: center;
gap: 8px;
padding: 10px 14px;
}
font-size: 11px;
flex-shrink: 0;
user-select: none;
}
flex: 1;
background: transparent;
border: none;
padding: 2px 0;
font-size: 13px;
font-family: 'Inter', 'Noto Sans JP', sans-serif;
outline: none;
letter-spacing: .03em;
}
font-size: 10px;
flex-shrink: 0;
}
list-style: none;
margin: 0;
padding: 4px 0;
max-height: 280px;
overflow-y: auto;
}
padding: 7px 14px;
cursor: pointer;
display: flex;
align-items: baseline;
gap: 8px;
}
}
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
font-size: 10px;
flex-shrink: 0;
}
padding: 10px 14px;
font-size: 11px;
}
font-size: 11px;
padding: 7px 14px;
display: flex;
justify-content: space-between;
}
`;
document.head.appendChild(style);
const project = scrapbox.Project.name;
/*──────────────────────────────
タイトルキャッシュ
起動後バックグラウンドで全タイトルを取得しておく
──────────────────────────────*/
let titleCache = []; // title, lower }
let cacheLoaded = false;
const loadTitleCache = async () => {
if (cacheLoaded) return;
try {
// Scrapbox は /api/pages/:project?limit=1000 で最大1000件
// 大規模wikiの場合は skip を使ってページングが必要
let skip = 0;
const limit = 1000;
while (true) {
const res = await fetch(/api/pages/${project}?limit=${limit}&skip=${skip});
const data = await res.json();
const pages = data.pages || [];
pages.forEach(p => titleCache.push({ title: p.title, lower: p.title.toLowerCase() }));
if (pages.length < limit) break;
skip += limit;
}
cacheLoaded = true;
} catch (e) {
console.warn("quick-link title cache load failed:", e); }
};
// バックグラウンドで先読み
loadTitleCache();
/*──────────────────────────────
ひらがな → ローマ字変換(簡易)
「きるけ」→ "kiruke" として fuzzy にかける
──────────────────────────────*/
const HIRA_TABLE = {
あ:"a",い:"i",う:"u",え:"e",お:"o",
か:"ka",き:"ki",く:"ku",け:"ke",こ:"ko",
さ:"sa",し:"shi",す:"su",せ:"se",そ:"so",
た:"ta",ち:"chi",つ:"tsu",て:"te",と:"to",
な:"na",に:"ni",ぬ:"nu",ね:"ne",の:"no",
は:"ha",ひ:"hi",ふ:"fu",へ:"he",ほ:"ho",
ま:"ma",み:"mi",む:"mu",め:"me",も:"mo",
や:"ya",ゆ:"yu",よ:"yo",
ら:"ra",り:"ri",る:"ru",れ:"re",ろ:"ro",
わ:"wa",を:"wo",ん:"n",
が:"ga",ぎ:"gi",ぐ:"gu",げ:"ge",ご:"go",
ざ:"za",じ:"ji",ず:"zu",ぜ:"ze",ぞ:"zo",
だ:"da",ぢ:"di",づ:"du",で:"de",ど:"do",
ば:"ba",び:"bi",ぶ:"bu",べ:"be",ぼ:"bo",
ぱ:"pa",ぴ:"pi",ぷ:"pu",ぺ:"pe",ぽ:"po",
きゃ:"kya",きゅ:"kyu",きょ:"kyo",
しゃ:"sha",しゅ:"shu",しょ:"sho",
ちゃ:"cha",ちゅ:"chu",ちょ:"cho",
にゃ:"nya",にゅ:"nyu",にょ:"nyo",
ひゃ:"hya",ひゅ:"hyu",ひょ:"hyo",
みゃ:"mya",みゅ:"myu",みょ:"myo",
りゃ:"rya",りゅ:"ryu",りょ:"ryo",
ぎゃ:"gya",ぎゅ:"gyu",ぎょ:"gyo",
じゃ:"ja",じゅ:"ju",じょ:"jo",
びゃ:"bya",びゅ:"byu",びょ:"byo",
ぴゃ:"pya",ぴゅ:"pyu",ぴょ:"pyo",
};
const toRomaji = (str) => {
// 長い組み合わせから先に置換
const sorted = Object.keys(HIRA_TABLE).sort((a, b) => b.length - a.length);
let result = str;
sorted.forEach(k => { result = result.replaceAll(k, HIRA_TABLEk); }); return result;
};
/*──────────────────────────────
Fuzzy match(キャッシュ対象)
query の各文字が title に順番に含まれるか
──────────────────────────────*/
const fuzzyMatch = (query, titleLower) => {
let qi = 0;
for (let i = 0; i < titleLower.length && qi < query.length; i++) {
if (titleLoweri === queryqi) qi++; }
return qi === query.length;
};
const searchCache = (query) => {
const q = query.toLowerCase();
const qRomaji = toRomaji(q); // ひらがなをローマ字化して両方試す
return titleCache
.filter(({ lower }) =>
lower.includes(q) ||
lower.includes(qRomaji) ||
fuzzyMatch(q, lower) ||
fuzzyMatch(qRomaji, lower)
)
.slice(0, 8)
.map(({ title }) => ({ title, source: "cache" }));
};
/*──────────────────────────────
Scrapbox 全文検索API
──────────────────────────────*/
const searchAPI = async (query) => {
try {
const res = await fetch(
/api/pages/${project}/search/query?q=${encodeURIComponent(query)}
);
const data = await res.json();
return (data.pages || []).slice(0, 8).map(p => ({ title: p.title, source: "api" }));
} catch {
return [];
}
};
/*──────────────────────────────
結果マージ(重複排除、APIを優先)
──────────────────────────────*/
const mergeResults = (apiResults, cacheResults) => {
const seen = new Set(apiResults.map(r => r.title));
const extra = cacheResults.filter(r => !seen.has(r.title));
};
/*──────────────────────────────
UI
──────────────────────────────*/
let isOpen = false;
const open = () => {
if (isOpen) return;
isOpen = true;
const overlay = document.createElement("div");
overlay.id = "ql-overlay";
overlay.innerHTML = `
<div id="ql-dialog">
<div id="ql-input-wrap">
<span id="ql-input-icon"> </span>
<input id="ql-input" type="text"
placeholder="ページ名を検索..."
autocomplete="off" spellcheck="false" />
<span id="ql-status"></span>
</div>
<ul id="ql-suggestions">
<li class="ql-empty">文字を入力して検索</li>
</ul>
<div id="ql-footer">
<span>↑↓ 選択 / Enter 挿入</span>
<span>Ctrl+Q / Esc 閉じる</span>
</div>
</div>
`;
document.body.appendChild(overlay);
const input = overlay.querySelector("#ql-input");
const list = overlay.querySelector("#ql-suggestions");
const status = overlay.querySelector("#ql-status");
let activeIndex = -1;
let debounceTimer;
let currentResults = [];
input.focus();
/*── 表示更新 ──*/
const render = (results, isLoading = false) => {
list.innerHTML = "";
activeIndex = -1;
currentResults = results;
status.textContent = isLoading ? "..." : "";
if (results.length === 0) {
const q = input.value.trim();
list.innerHTML = q
? <li class="ql-empty">該当なし — Enterで「${q}」を直接挿入</li>
: <li class="ql-empty">文字を入力して検索</li>;
return;
}
results.forEach((r) => {
const li = document.createElement("li");
li.className = "ql-item";
li.innerHTML = `
<span class="ql-item-title">${escapeHtml(r.title)}</span>
`;
li.addEventListener("mousedown", (e) => {
e.preventDefault();
confirm(r.title);
});
list.appendChild(li);
});
};
/*── 検索実行 ──*/
const doSearch = async (query) => {
if (!query.trim()) { render([]); return; }
// キャッシュ結果を即時表示
const cacheResults = searchCache(query);
render(cacheResults, true);
// API検索も並行して実行
const apiResults = await searchAPI(query);
const merged = mergeResults(apiResults, cacheResults);
render(merged, false);
};
input.addEventListener("input", () => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => doSearch(input.value), 150);
});
/*── キーボード ──*/
input.addEventListener("keydown", (e) => {
const items = list.querySelectorAll(".ql-item");
if (e.key === "ArrowDown") {
e.preventDefault();
activeIndex = Math.min(activeIndex + 1, items.length - 1);
items.forEach((el, i) => el.classList.toggle("active", i === activeIndex));
itemsactiveIndex?.scrollIntoView({ block: "nearest" }); } else if (e.key === "ArrowUp") {
e.preventDefault();
activeIndex = Math.max(activeIndex - 1, -1);
items.forEach((el, i) => el.classList.toggle("active", i === activeIndex));
itemsactiveIndex?.scrollIntoView({ block: "nearest" }); } else if (e.key === "Enter") {
e.preventDefault();
const target =
activeIndex >= 0
: input.value.trim();
if (target) confirm(target);
} else if (e.key === "Escape") {
e.preventDefault();
close();
}
});
overlay.addEventListener("click", (e) => {
if (e.target === overlay) close();
});
/*── 確定・閉じる ──*/
const confirm = (title) => {
close();
insertText({ text: [${title}] });
};
const close = () => {
overlay.remove();
isOpen = false;
};
};
/*── エスケープ ──*/
const escapeHtml = (str) =>
str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
scrapbox.PageMenu.addMenu({
title: "リンク挿入",
onClick: open,
});
/*── Ctrl+Q で起動 ──*/
document.addEventListener("keydown", (e) => {
if (e.ctrlKey && e.key.toLowerCase() === "q") {
e.preventDefault();
if (isOpen) {
// 既に開いていたら閉じる(トグル)
document.querySelector("#ql-overlay")?.remove();
isOpen = false;
} else {
open();
}
}
});
})();
code:year-input-customization.js
import { insertText } from "/api/code/customize/scrapbox-insert-text/script.js";
(function () {
"use strict";
const style = document.createElement("style");
style.textContent = `
.popup-ui {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px;
border-radius: 0;
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
z-index: 9999;
font-size: 13px;
font-family: 'Inter', 'Noto Sans JP', sans-serif;
font-weight: 400;
letter-spacing: .03em;
display: flex;
flex-direction: column;
gap: 0;
}
.popup-ui.category-select {
width: 220px;
padding: 0;
}
.popup-ui.detail-input {
width: 240px;
}
.popup-ui label {
font-size: 11px;
font-weight: 400;
display: flex;
flex-direction: column;
gap: 4px;
margin-bottom: 12px;
}
.popup-ui .checkbox-label {
flex-direction: row;
align-items: center;
gap: 6px;
cursor: pointer;
}
.popup-ui .checkbox-label:hover span,
.popup-ui .checkbox-label:has(input:focus) span {
text-decoration: underline;
}
width: auto;
margin: 0;
cursor: pointer;
}
outline: none;
}
.popup-ui input, .popup-ui select {
border-radius: 0;
padding: 6px 8px;
width: 100%;
font-size: 13px;
font-family: 'Inter', 'Noto Sans JP', sans-serif;
font-weight: 400;
letter-spacing: .03em;
}
.popup-ui input:focus, .popup-ui select:focus {
outline: none;
}
.popup-ui button {
background: transparent;
border: none;
border-radius: 0;
padding: 8px 12px;
cursor: pointer;
font-size: 11px;
font-family: 'Inter', 'Noto Sans JP', sans-serif;
font-weight: 400;
letter-spacing: .03em;
text-transform: uppercase;
text-decoration: none;
}
.popup-ui button:hover {
text-decoration: underline;
}
.category-btn {
background: transparent;
border: none;
border-radius: 0;
padding: 14px 20px;
cursor: pointer;
text-align: left;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 13px;
font-weight: 400;
text-decoration: none;
}
.category-btn:last-of-type {
border-bottom: none;
}
.category-btn:hover {
text-decoration: underline;
}
.category-btn .key-hint {
background: transparent;
padding: 0;
border-radius: 0;
font-size: 11px;
font-family: 'Inter', monospace;
font-weight: 400;
}
.popup-ui .checkbox-label {
flex-direction: row;
align-items: center;
gap: 6px;
cursor: pointer;
}
.popup-ui .checkbox-label:hover span,
.popup-ui .checkbox-label:has(input:focus) span {
text-decoration: underline;
}
width: auto;
margin: 0;
cursor: pointer;
}
outline-offset: 2px;
}
.shortcut-hint {
font-size: 11px;
font-weight: 400;
text-align: center;
padding: 14px 20px;
}
`;
document.head.appendChild(style);
// Scrapboxページメニューに登録
scrapbox.PageMenu.addMenu({
title: "+年代/カテゴリ",
onClick: showCategorySelect,
});
// Ctrl+Y でも起動可能
document.addEventListener("keydown", (e) => {
if (e.ctrlKey && e.key.toLowerCase() === "y") {
e.preventDefault();
showCategorySelect();
}
});
function showCategorySelect() {
if (document.querySelector(".popup-ui")) return; // 二重防止
const ui = document.createElement("div");
ui.className = "popup-ui category-select";
ui.innerHTML = `
<button class="category-btn" data-category="anime">
<span>アニメ</span>
<span class="key-hint">1</span>
</button>
<button class="category-btn" data-category="game">
<span>ゲーム</span>
<span class="key-hint">2</span>
</button>
<button class="category-btn" data-category="movie">
<span>映画</span>
<span class="key-hint">3</span>
</button>
<button class="category-btn" data-category="person">
<span>人物</span>
<span class="key-hint">4</span>
</button>
<button class="category-btn" data-category="other">
<span>その他</span>
<span class="key-hint">5</span>
</button>
<div class="shortcut-hint">数字キーまたはクリックで選択 / ESC: キャンセル</div>
`;
document.body.appendChild(ui);
// ボタンクリックでカテゴリ選択
ui.querySelectorAll(".category-btn").forEach((btn) => {
btn.addEventListener("click", () => {
const category = btn.dataset.category;
ui.remove();
showDetailInput(category);
});
});
// キーボードショートカット
ui.addEventListener("keydown", (e) => {
if (e.key >= "1" && e.key <= "5") {
e.preventDefault();
ui.remove();
showDetailInput(category);
}
if (e.key === "Escape") {
e.preventDefault();
ui.remove();
}
});
// フォーカスしてキー入力を受け付ける
ui.setAttribute("tabindex", "0");
ui.focus();
}
function showDetailInput(selectedCategory) {
const ui = document.createElement("div");
ui.className = "popup-ui detail-input";
const categoryNames = {
anime: "アニメ",
game: "ゲーム",
movie: "映画",
person: "人物",
other: "その他"
};
const showDecadeOption = selectedCategory !== "anime" && selectedCategory !== "game" && selectedCategory !== "person";
ui.innerHTML = `
<label for="category">カテゴリ:
<select id="category">
<option value="anime">アニメ</option>
<option value="game">ゲーム</option>
<option value="movie">映画</option>
<option value="person">人物</option>
<option value="other">その他</option>
</select>
</label>
<label for="tagType">入力形式:
<select id="tagType">
<option value="hashtag">#ハッシュタグ</option>
<option value="link">リンク</option> </select>
</label>
<label id="customCategoryLabel" style="display:none;">カテゴリ名:
<input id="customCategory" type="text" placeholder="例: 書籍">
</label>
<label id="yearLabel">年(例: 2025):
<input id="year" type="text" placeholder="2025">
</label>
<label id="deathLabel" style="display:none;">没年(例: 1988):
<input id="deathYear" type="text" placeholder="空白可">
</label>
<label id="decadeLabel" class="checkbox-label" style="display:${showDecadeOption ? 'flex' : 'none'};">
<input id="includeDecade" type="checkbox">
<span>年代タグを追加</span>
</label>
<div style="display:flex; gap:8px; justify-content:flex-end;">
<button id="okBtn">OK</button>
<button id="cancelBtn">キャンセル</button>
</div>
`;
document.body.appendChild(ui);
const category = ui.querySelector("#category");
const tagType = ui.querySelector("#tagType");
const yearInput = ui.querySelector("#year");
const deathYearInput = ui.querySelector("#deathYear");
const customCategoryInput = ui.querySelector("#customCategory");
const includeDecadeCheckbox = ui.querySelector("#includeDecade");
const okBtn = ui.querySelector("#okBtn");
const cancelBtn = ui.querySelector("#cancelBtn");
const deathLabel = ui.querySelector("#deathLabel");
const customCategoryLabel = ui.querySelector("#customCategoryLabel");
const decadeLabel = ui.querySelector("#decadeLabel");
const yearLabel = ui.querySelector("#yearLabel");
// 選択されたカテゴリを設定
category.value = selectedCategory;
// カテゴリに応じた初期設定
function updateUI() {
const isPerson = category.value === "person";
const isAnime = category.value === "anime";
const isGame = category.value === "game";
const isOther = category.value === "other";
deathLabel.style.display = isPerson ? "block" : "none";
customCategoryLabel.style.display = isOther ? "block" : "none";
decadeLabel.style.display = (isAnime || isGame || isPerson) ? "none" : "flex";
if (isAnime || isGame) {
tagType.value = "hashtag";
} else {
tagType.value = "link";
}
if (isPerson) {
yearLabel.childNodes0.textContent = "生年(例: 1952):"; } else {
yearLabel.childNodes0.textContent = "年(例: 2025):"; }
}
updateUI();
// カテゴリ変更時の処理
category.addEventListener("change", updateUI);
// キーボードショートカット(入力欄内のみ)
ui.addEventListener("keydown", (e) => {
if (e.key === "Enter" && e.target.tagName === "INPUT") {
e.preventDefault();
apply();
}
if (e.key === "Escape") {
e.preventDefault();
closeUI();
}
if (e.key === "Tab") {
e.preventDefault();
// その他の場合はカスタムカテゴリ入力を年の前に追加
if (category.value === "other") {
focusableElements.push(customCategoryInput);
}
focusableElements.push(yearInput);
// 人物の場合は没年入力も追加
if (category.value === "person") {
focusableElements.push(deathYearInput);
}
// 年代チェックボックスが表示されている場合は追加
if (decadeLabel.style.display !== "none") {
focusableElements.push(includeDecadeCheckbox);
}
// OKとキャンセルボタンはループに含めない
const currentElement = document.activeElement;
// ボタンからTabした場合は最初の要素へ
if (currentElement === okBtn || currentElement === cancelBtn) {
focusableElements0.focus(); } else {
const currentIndex = focusableElements.indexOf(currentElement);
const nextIndex = (currentIndex + 1) % focusableElements.length;
}
}
// セレクトボックスでの矢印キーループ
if ((e.key === "ArrowDown" || e.key === "ArrowUp") && e.target.tagName === "SELECT") {
e.preventDefault();
const select = e.target;
const options = Array.from(select.options);
const currentIndex = select.selectedIndex;
let newIndex;
if (e.key === "ArrowDown") {
newIndex = (currentIndex + 1) % options.length;
} else {
newIndex = (currentIndex - 1 + options.length) % options.length;
}
select.selectedIndex = newIndex;
select.dispatchEvent(new Event("change"));
}
// チェックボックスのスペースキー切り替え
if (e.key === " " && e.target.type === "checkbox") {
e.preventDefault();
e.target.checked = !e.target.checked;
}
});
cancelBtn.onclick = closeUI;
okBtn.onclick = apply;
// 初期フォーカス: その他の場合はカスタムカテゴリ、それ以外は年入力欄
if (selectedCategory === "other") {
customCategoryInput.focus();
} else {
yearInput.focus();
}
function closeUI() {
ui.remove();
}
function apply() {
const year = yearInput.value.trim();
const deathYear = deathYearInput.value.trim();
const categoryVal = category.value;
const tagForm = tagType.value;
const customCat = customCategoryInput.value.trim();
const includeDecade = includeDecadeCheckbox ? includeDecadeCheckbox.checked : false;
if (!year) return closeUI();
let textToInsert = "";
let hashtagToInsert = "";
if (categoryVal === "person") {
// 世紀と時期を計算
const birthYear = parseInt(year);
const century = Math.ceil(birthYear / 100);
let period;
const yearInCentury = ((birthYear - 1) % 100) + 1;
if (yearInCentury <= 33) {
period = "初頭";
} else if (yearInCentury <= 66) {
period = "半ば";
} else {
period = "末期";
}
const centuryTag = ${century}世紀${period}-人物;
const birthLine = 生年: ${year}年;
const deathLine = deathYear ? / 没年: ${deathYear}年 : / 没年: ;
textToInsert = ${birthLine}${deathLine};
hashtagToInsert = [${centuryTag}];
} else if (categoryVal === "anime") {
const decade = Math.floor(year / 10) * 10;
const yearTag = ${year}年-アニメ;
const decadeTag = ${decade}年代-アニメ;
textToInsert =
tagForm === "hashtag"
? #${yearTag} #${decadeTag}
: [${yearTag}] [${decadeTag}];
} else if (categoryVal === "game") {
const decade = Math.floor(year / 10) * 10;
const yearTag = ${year}年-ゲーム;
const decadeTag = ${decade}年代-ゲーム;
textToInsert =
tagForm === "hashtag"
? #${yearTag} #${decadeTag}
: [${yearTag}] [${decadeTag}];
} else if (categoryVal === "movie") {
const yearTag = ${year}年-映画;
const decadeTag = includeDecade ? ${Math.floor(year / 10) * 10}年代-映画 : null;
if (tagForm === "hashtag") {
textToInsert = decadeTag ? #${yearTag} #${decadeTag} : #${yearTag};
} else {
textToInsert = decadeTag ? [${yearTag}] [${decadeTag}] : [${yearTag}];
}
} else if (categoryVal === "other") {
if (customCat) {
const yearTag = ${year}年-${customCat};
const decadeTag = includeDecade ? ${Math.floor(year / 10) * 10}年代-${customCat} : null;
if (tagForm === "hashtag") {
textToInsert = decadeTag ? #${yearTag} #${decadeTag} : #${yearTag};
} else {
textToInsert = decadeTag ? [${yearTag}] [${decadeTag}] : [${yearTag}];
}
} else {
textToInsert = tagForm === "hashtag" ? #${year}年 : [${year}年];
}
} else {
textToInsert = tagForm === "hashtag" ? #${year}年 : [${year}年];
}
// 人物の場合はページ最下部にハッシュタグを追加
if (hashtagToInsert) {
// 現在のページの全行を取得
const lines = scrapbox.Page.lines || [];
// 最終行が空でない場合は改行を追加
const finalText = lastLine && lastLine.text.trim() !== ""
? ${textToInsert}\n\n${hashtagToInsert}
: ${textToInsert}\n${hashtagToInsert};
insertText({ text: finalText });
} else {
insertText({ text: textToInsert });
}
closeUI();
}
}
})();
code:scrapbox-url-customizer.js
function ce(e){return Array.isArray(e)}function M(e){return typeof e=="string"}var De=(e,r)=>{if(!(e instanceof HTMLDivElement))throw new TypeError("${r}" must be HTMLDivElememt but actual is "${e}")};var Ve=(e,r)=>{if(!(e instanceof HTMLTextAreaElement))throw new TypeError("${r}" must be HTMLTextAreaElement but actual is "${e}")};var q=()=>{let e=document.getElementById("text-input");if(e)return Ve(e,"textarea#text-input"),e};var We=()=>Xt(document.getElementsByClassName("status-bar")?.0,"div.status-bar"),Xt=(e,r)=>{if(e)return De(e,r),e};var Io=2**31-1;var qe=e=>{let r=q();if(!r)throw Error("#text-input is not ditected.");r.focus(),r.value=e;let t=new InputEvent("input",{bubbles:!0});return r.dispatchEvent(t),scrapbox.Page.waitForSave()};var Ke=()=>{let e=We();if(!e)throw new Error("div.status-bar can't be found");let r=document.createElement("div");return e.append(r),{render:(...t)=>{r.textContent="";let o=ze(...t);o&&r.append(o)},dispose:()=>r.remove(),Symbol.dispose:()=>r.remove()}},ze=(...e)=>{let r=e.flatMap(o=>{switch(o.type){case"spinner":returnor();case"check-circle":returnnr();case"exclamation-triangle":returnsr();case"text":returnpe(o.text);case"group":{let n=ze(...o.items);return n?n:[]}}});if(r.length===0)return;if(r.length===1)return r0;let t=document.createElement("span");return t.classList.add("item-group"),t.append(...r),t},pe=e=>{let r=document.createElement("span");return r.classList.add("item"),r.append(e),r},or=()=>{let e=document.createElement("i");return e.classList.add("fa","fa-spinner"),pe(e)},nr=()=>{let e=document.createElement("i");return e.classList.add("kamon","kamon-check-circle"),pe(e)},sr=()=>{let e=document.createElement("i");return e.classList.add("fas","fa-exclamation-triangle"),pe(e)};var Ae=(e,...r)=>{let t=r.reduce((o,n)=>M(o)?o:o instanceof Promise?o.then(s=>M(s)?s:n(s)):n(o),e);return t instanceof Promise?t.then(o=>${o}):${e}};function N(e){return e.val}function S(e){return e.err}var Ye=" must not return ",ir="transformer",cr="recoverer",pr="defaultValue",ue=ir+Ye,V="called with ",me=pr+" must not be ",le=cr+Ye;var ur="Ok",Xe="Err",Je=V+Xe,Qe=V+ur,mr="Carrying E in "+Xe+" instead of throwing it directly. See .cause",Me="an instance of Error of the current realm.",ls="The thrown value is not "+Me,fs="The contained E should be "+Me,lr="This .cause is not "+Me;function w(e){return e.ok}function L(e){return{ok:!0,val:e,err:null}}function E(e){return!e.ok}function P(e){return{ok:!1,val:null,err:e}}function I(e){return Ze(e,Je)}function v(e){return et(e,Qe)}function Ze(e,r){if(E(e))throw new TypeError(r);return e.val}function et(e,r){if(w(e))throw new TypeError(r);return e.err}async function W(e,r){if(E(e))return e;let t=N(e),o=await r(t);return L(o)}function Pe(e,r,t){if(w(e)){let n=N(e);return t(n)}let o=S(e);return r(o)}var fe="null",ha=ue+fe,Er=V+fe,Ta=me+fe,xa=le+fe;var de="undefined",Na=ue+de,Rr=V+de,La=me+de,Ua=le+de;var K=e=>e.ok?L(e):P({name:"HTTPError",message:${e.status} ${e.statusText},response:e});var rt=e=>window.GM_fetch?.(https://cdn.syndication.twimg.com/tweet-result?id=${e}&token=x)?.then?.(r=>W(K(r),t=>t.json()));var Ee=e=>{let{fetch:r=globalThis.fetch,...t}=e;return{fetch:r,...t}},ot=e=>typeof e=="object"&&e!==null;var Q=class e extends Error{name="UnexpectedResponseError";status;statusText;body;path;constructor(r){super(${r.status} ${r.statusText} when fetching ${r.path.toString()}),this.status=r.status,this.statusText=r.statusText,this.body=r.body,this.path=r.path,Error.captureStackTrace&&Error.captureStackTrace(this,e)}};var Re=async e=>{let r=await e.text();if(e.ok)return L(r);if(e.status===400)return P({name:"BadRequestError",message:r});try{let t=JSON.parse(r);if(!ot(t)||typeof t.message!="string")throw new Q({status:e.status,statusText:e.statusText,body:r,path:new URL(e.url)});switch(e.status){case 401:return P({name:"UnauthorizedError",message:t.message});case 403:return P({name:"NotPrivilegeError",message:t.message});case 404:return P({name:"NotFoundError",message:t.message});case 422:return P({name:"InvalidParameterError",message:t.message});case 429:return P({name:"RateLimitError",message:t.message});default:throw new Q({status:e.status,statusText:e.statusText,body:r,path:new URL(e.url)})}}catch(t){throw t instanceof SyntaxError?new Q({status:e.status,statusText:e.statusText,body:r,path:new URL(e.url)}):t}};var nt=async(e,r)=>{let{title:t,description:o,metadataIsPublic:n,collectionId:s,refererURL:a,accessToken:p,created:i,app:f,fetch:l}=Ee(r),u=new FormData;u.append("imagedata",e),u.append("access_token",p),a&&u.append("referer_url",a.toString()),f!==void 0&&u.append("app",f),t!==void 0&&u.append("title",t),o!=null&&u.append("desc",o),s&&u.append("collection_id",s),n&&u.append("metadata_is_public","true"),i!==void 0&&u.append("created_at",${i});let A=await l("https://upload.gyazo.com/api/upload",{method:"POST",mode:"cors",credentials:"omit",body:u}),C=await Re(A);return E(C)?C:L(JSON.parse(I(C)))};function O(e){return e.val}function U(e){return e.err}var st=" must not return ",gr="transformer",hr="recoverer",Tr="defaultValue",z=gr+st,H="called with ",Y=Tr+" must not be ",X=hr+st;var xr="Ok",at="Err",it=H+at,_r=H+xr,wr="Carrying E in "+at+" instead of throwing it directly. See .cause",Ie="an instance of Error of the current realm.",mp="The thrown value is not "+Ie,lp="The contained E should be "+Ie,Or="This .cause is not "+Ie;function _(e){return e.ok}function R(e){return{ok:!0,val:e,err:null}}function m(e){return!e.ok}function b(e){return{ok:!1,val:null,err:e}}function d(e){return ct(e,it)}function ct(e,r){if(m(e))throw new TypeError(r);return e.val}function Z(e,r){if(m(e))return e;let t=O(e),o=r(t);return R(o)}async function g(e,r){if(m(e))return e;let t=O(e),o=await r(t);return R(o)}async function x(e,r){if(_(e))return e;let t=U(e),o=await r(t);return b(o)}async function ye(e,r){if(_(e))return e;let t=U(e);return await r(t)}var ge="null",Ou=z+ge,Lr=H+ge,bu=Y+ge,Nu=X+ge;var he="undefined",Au=z+he,Ur=H+he,Mu=Y+he,Pu=X+he;var h=e=>e.ok?R(e):b({name:"HTTPError",message:${e.status} ${e.statusText},response:e});var ut=async(e,r)=>{let t=new Request(e,r);try{return R(await globalThis.fetch(t))}catch(o){if(o instanceof DOMException&&o.name==="AbortError")return b({name:"AbortError",message:o.message,request:t});if(o instanceof TypeError)return b({name:"NetworkError",message:o.message,request:t});throw o}};var y=e=>{let{fetch:r=ut,hostName:t="scrapbox.io",...o}=e;return{fetch:r,hostName:t,...o}};var mt=e=>{let{sid:r,hostName:t}=y(e??{});return new Request(https://${t}/api/users/me,r?{headers:{Cookie:T(r)}}:void 0)},lt=e=>g(h(e),async r=>await r.json()),ft=(()=>{let e=async r=>{let{fetch:t,...o}=y(r??{}),n=await t(mt(o));return m(n)?n:lt(d(n))};return e.toRequest=mt,e.fromResponse=lt,e})();var T=e=>connect.sid=${e},G=async e=>{let r=e?.csrf??globalThis._csrf;return r?R(r):Z(await ft(e),t=>t.csrfToken)};function Te(e,r={}){if(e===null)return"null";if(Array.isArray(e))return Ar(e,r);switch(typeof e){case"string":return JSON.stringify(e);case"bigint":return${e}n;case"object":return e.constructor?.name!=="Object"?e.constructor?.name:Mr(e,r);case"function":return e.name||"(anonymous)"}return e?.toString()??"undefined"}function Ar(e,r){let{threshold:t=20}=r,o=e.map(a=>Te(a,r)),n=o.join(", ");if(n.length<=t)return[${n}];let s=o.join(`, );return[
${dt(2,s)}
]}function Mr(e,r){let{threshold:t=20}=r,o=[...Object.keys(e),...Object.getOwnPropertySymbols(e)].map(a=>${a.toString()}: ${Te(ea,r)}),n=o.join(", ");if(n.length<=t)return{${n}};let s=o.join(, );return{
${dt(2,s)}
}}function dt(e,r){let t=" ".repeat(e);return r.split(
).map(o=>${t}${o}).join(
)}function xe(e,r,...t){let o;return Object.defineProperties(e,{name:{get:()=>o||(o=${r}(${t.map(n=>Te(n)).join(", ")}),o)}})}function Et(e){return xe(r=>ce(r)&&r.every(t=>e(t)),"isArrayOf",e)}function Se(e){let r=new Set(e);return xe(t=>r.has(t),"isLiteralOneOf",e)}function Ce(e){return e!=null&&!Array.isArray(e)&&typeof e=="object"}var F=async(e,r)=>{let t=e.response.clone(),o=Se(r);try{let n=await t.json();if(!Ce(n))return;if(t.status===422){if(!M(n.message))return;for(let s of["NoQueryError","InvalidURLError"])if(r.includes(s))return{name:s,message:n.message}}return!o(n.name)||!M(n.message)?void 0:n.name==="NotLoggedInError"?!Ce(n.detals)||!M(n.detals.project)||!Et(Pr)(n.detals.loginStrategies)?void 0:{name:n.name,message:n.message,details:{project:n.detals.project,loginStrategies:n.detals.loginStrategies}}:{name:n.name,message:n.message}}catch(n){if(n instanceof SyntaxError)return;throw n}},Pr=Se(["google","github","microsoft","gyazo","email","saml","easy-trial"]);var _e="null or undefined",J=z+_e,Ir=H+_e,ve=Y+_e,we=X+_e;function B(e){return e==null}function Oe(e){return B(e)?b(void 0):R(e)}var Rt=(e,r)=>{let{sid:t,hostName:o}=y(r??{});return new Request(https://${o}/api/projects/${e},t?{headers:{Cookie:T(t)}}:void 0)},yt=async e=>g(await x(h(e),async r=>await F(r,["NotFoundError","NotLoggedInError","NotMemberError"])??r),r=>r.json()),gt=(()=>{let e=async(r,t)=>{let{fetch:o}=y(t??{}),n=Rt(r,t),s=await o(n);return m(s)?s:yt(d(s))};return e.toRequest=Rt,e.fromResponse=yt,e})();var ht=async(e,r)=>{let{sid:t,hostName:o,fetch:n}=y(r??{}),s=await G(r);if(m(s))return s;let a=new Request(https://${o}/api/embed-text/url?url=${encodeURIComponent(${e})},{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8","X-CSRF-TOKEN":d(s),...t?{Cookie:T(t)}:{}},body:JSON.stringify({timeout:3e3})}),p=await n(a);return m(p)?p:g(await x(h(d(p)),async i=>await F(i,["SessionError","BadRequestError","InvalidURLError"])??i),async i=>{let{title:f}=await i.json();return f})};var Tt=async(e,r)=>{let{sid:t,hostName:o,fetch:n}=y(r??{}),s=await G(r);if(m(s))return s;let a=new Request(https://${o}/api/embed-text/twitter?url=${encodeURIComponent(${e})},{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8","X-CSRF-TOKEN":d(s),...t?{Cookie:T(t)}:{}},body:JSON.stringify({timeout:3e3})}),p=await n(a);return m(p)?p:x(await g(h(d(p)),i=>i.json()),async i=>i.response.status===422?{name:"InvalidURLError",message:(await i.response.json()).message}:await F(i,["SessionError","BadRequestError"])??i)};var xt=async e=>{let{fetch:r,sid:t,hostName:o,gyazoTeamsName:n}=y(e??{}),s=new Request(https://${o}/api/login/gyazo/oauth-upload/token${n??gyazoTeamsName=${n}:""},t?{headers:{Cookie:T(t)}}:void 0),a=await r(s);return m(a)?a:g(await x(h(d(a)),async p=>await F(p,["NotLoggedInError"])??p),p=>p.json().then(i=>i.token))};var Ot=e=>{let r=typeof e=="string"?new TextEncoder().encode(e):ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),t=[1732584193,4023233417,2562383102,271733878],o=new Uint8Array(Be),n=0,s=0,a=0;[t,o,n,s,a]=wt(t,o,n,s,a,r);let p=Be-n;p<9&&(p+=Be);let i=new Uint8Array(p);i[0]=128,[s,a]=[s<<3,a<<3|s>>>29],i[i.length-8]=s&255,i[i.length-7]=s>>>8&255,i[i.length-6]=s>>>16&255,i[i.length-5]=s>>>24&255,i[i.length-4]=a&255,i[i.length-3]=a>>>8&255,i[i.length-2]=a>>>16&255,i[i.length-1]=a>>>24&255,[t,o,n,s,a]=wt(t,o,n,s,a,new Uint8Array(i.buffer));let f=new ArrayBuffer(16),l=new DataView(f);return l.setUint32(0,t[0],!0),l.setUint32(4,t[1],!0),l.setUint32(8,t[2],!0),l.setUint32(12,t[3],!0),f},Be=64,c=(e,r)=>e<<r|e>>>32-r,k=(e,r)=>e[r]|e[r+1]<<8|e[r+2]<<16|e[r+3]<<24,_t=(e,r)=>{let[t,o,n,s]=e,a=k(r,0),p=k(r,4),i=k(r,8),f=k(r,12),l=k(r,16),u=k(r,20),A=k(r,24),C=k(r,28),D=k(r,32),te=k(r,36),re=k(r,40),oe=k(r,44),ne=k(r,48),se=k(r,52),ae=k(r,56),ie=k(r,60);return t=o+c(((n^s)&o^s)+t+a+3614090360,7),s=t+c(((o^n)&t^n)+s+p+3905402710,12),n=s+c(((t^o)&s^o)+n+i+606105819,17),o=n+c(((s^t)&n^t)+o+f+3250441966,22),t=o+c(((n^s)&o^s)+t+l+4118548399,7),s=t+c(((o^n)&t^n)+s+u+1200080426,12),n=s+c(((t^o)&s^o)+n+A+2821735955,17),o=n+c(((s^t)&n^t)+o+C+4249261313,22),t=o+c(((n^s)&o^s)+t+D+1770035416,7),s=t+c(((o^n)&t^n)+s+te+2336552879,12),n=s+c(((t^o)&s^o)+n+re+4294925233,17),o=n+c(((s^t)&n^t)+o+oe+2304563134,22),t=o+c(((n^s)&o^s)+t+ne+1804603682,7),s=t+c(((o^n)&t^n)+s+se+4254626195,12),n=s+c(((t^o)&s^o)+n+ae+2792965006,17),o=n+c(((s^t)&n^t)+o+ie+1236535329,22),t=o+c(((o^n)&s^n)+t+p+4129170786,5),s=t+c(((t^o)&n^o)+s+A+3225465664,9),n=s+c(((s^t)&o^t)+n+oe+643717713,14),o=n+c(((n^s)&t^s)+o+a+3921069994,20),t=o+c(((o^n)&s^n)+t+u+3593408605,5),s=t+c(((t^o)&n^o)+s+re+38016083,9),n=s+c(((s^t)&o^t)+n+ie+3634488961,14),o=n+c(((n^s)&t^s)+o+l+3889429448,20),t=o+c(((o^n)&s^n)+t+te+568446438,5),s=t+c(((t^o)&n^o)+s+ae+3275163606,9),n=s+c(((s^t)&o^t)+n+f+4107603335,14),o=n+c(((n^s)&t^s)+o+D+1163531501,20),t=o+c(((o^n)&s^n)+t+se+2850285829,5),s=t+c(((t^o)&n^o)+s+i+4243563512,9),n=s+c(((s^t)&o^t)+n+C+1735328473,14),o=n+c(((n^s)&t^s)+o+ne+2368359562,20),t=o+c((o^n^s)+t+u+4294588738,4),s=t+c((t^o^n)+s+D+2272392833,11),n=s+c((s^t^o)+n+oe+1839030562,16),o=n+c((n^s^t)+o+ae+4259657740,23),t=o+c((o^n^s)+t+p+2763975236,4),s=t+c((t^o^n)+s+l+1272893353,11),n=s+c((s^t^o)+n+C+4139469664,16),o=n+c((n^s^t)+o+re+3200236656,23),t=o+c((o^n^s)+t+se+681279174,4),s=t+c((t^o^n)+s+a+3936430074,11),n=s+c((s^t^o)+n+f+3572445317,16),o=n+c((n^s^t)+o+A+76029189,23),t=o+c((o^n^s)+t+te+3654602809,4),s=t+c((t^o^n)+s+ne+3873151461,11),n=s+c((s^t^o)+n+ie+530742520,16),o=n+c((n^s^t)+o+i+3299628645,23),t=o+c((n^(o|~s))+t+a+4096336452,6),s=t+c((o^(t|~n))+s+C+1126891415,10),n=s+c((t^(s|~o))+n+ae+2878612391,15),o=n+c((s^(n|~t))+o+u+4237533241,21),t=o+c((n^(o|~s))+t+ne+1700485571,6),s=t+c((o^(t|~n))+s+f+2399980690,10),n=s+c((t^(s|~o))+n+re+4293915773,15),o=n+c((s^(n|~t))+o+p+2240044497,21),t=o+c((n^(o|~s))+t+D+1873313359,6),s=t+c((o^(t|~n))+s+ie+4264355552,10),n=s+c((t^(s|~o))+n+A+2734768916,15),o=n+c((s^(n|~t))+o+se+1309151649,21),t=o+c((n^(o|~s))+t+l+4149444226,6),s=t+c((o^(t|~n))+s+oe+3174756917,10),n=s+c((t^(s|~o))+n+i+718787259,15),o=n+c((s^(n|~t))+o+te+3951481745,21),[e[0]+t>>>0,e[1]+o>>>0,e[2]+n>>>0,e[3]+s>>>0]},wt=(e,r,t,o,n,s)=>{let a=64-t;if(s.length<a)r.set(s,t),t+=s.length;else{r.set(s.slice(0,a),t),e=_t(e,r);let p=a;for(;p+64<=s.length;)e=_t(e,s.slice(p,p+64)),p+=64;r.fill(0).set(s.slice(p),0),t=s.length-p}return[o,n]=Cr(o,n,s.length),[e,r,t,o,n]},Cr=(e,r,t)=>(e+=t,e>4294967295&&(r+=1),[e>>>0,r]);var vr=new TextEncoder().encode("0123456789abcdef"),bt=new Uint8Array(128).fill(16);vr.forEach((e,r)=>bt[e]=r);new TextEncoder().encode("ABCDEF").forEach((e,r)=>bt[e]=r+10);function Nt(e){return e*2}function Lt(e,r,t,o){for(;r<e.length;++r){let n=e[r];e[t++]=o[n>>4],e[t++]=o[n&15]}return t}function Ut(e,r){let t=e.length;if(e.byteOffset){let o=new Uint8Array(e.buffer);o.set(e),e=o.subarray(0,t)}return e=new Uint8Array(e.buffer.transfer(r)),e.set(e.subarray(0,t),r-t),[e,r-t]}var Ft=new TextEncoder().encode("0123456789abcdef"),kt=new Uint8Array(128).fill(16);Ft.forEach((e,r)=>kt[e]=r);new TextEncoder().encode("ABCDEF").forEach((e,r)=>kt[e]=r+10);function At(e){typeof e=="string"?e=new TextEncoder().encode(e):e instanceof ArrayBuffer?e=new Uint8Array(e).slice():e=e.slice();let[r,t]=Ut(e,Nt(e.length));return Lt(r,t,0,Ft),new TextDecoder().decode(r)}var Mt=async(e,r,t)=>{let o=${At(Ot(await e.arrayBuffer()))},n=await Br(e,r,o,t);if(m(n))return n;let s=d(n);if("embedUrl"in s)return R(s);let a=await Hr(s.signedUrl,e,t);return m(a)?a:Gr(r,s.fileId,o,t)},Br=async(e,r,t,o)=>{let{sid:n,hostName:s,fetch:a,csrf:p}=y(o??{}),i={md5:t,size:e.size,contentType:e.type,name:e.name},f=await ye(Oe(p),()=>G(o));if(m(f))return f;let l=new Request(https://${s}/api/gcs/${r}/upload-request,{method:"POST",body:JSON.stringify(i),headers:{"Content-Type":"application/json;charset=utf-8","X-CSRF-TOKEN":d(f),...n?{Cookie:T(n)}:{}}}),u=await a(l);return m(u)?u:g(await x(h(d(u)),async A=>A.response.status===402?{name:"FileCapacityError",message:(await A.response.json()).message}:A),A=>A.json())},Hr=async(e,r,t)=>{let{sid:o,fetch:n}=y(t??{}),s=await n(e,{method:"PUT",body:r,headers:{"Content-Type":r.type,...o?{Cookie:T(o)}:{}}});return m(s)?s:Z(await x(h(d(s)),async a=>a.response.headers.get("Content-Type")?.includes?.("/xml")?{name:"GCSError",message:await a.response.text()}:a),()=>{})},Gr=async(e,r,t,o)=>{let{sid:n,hostName:s,fetch:a,csrf:p}=y(o??{}),i=await ye(Oe(p),()=>G(o));if(m(i))return i;let f=new Request(https://${s}/api/gcs/${e}/verify,{method:"POST",body:JSON.stringify({md5:t,fileId:r}),headers:{"Content-Type":"application/json;charset=utf-8","X-CSRF-TOKEN":d(i),...n?{Cookie:T(n)}:{}}}),l=await a(f);return m(l)?l:g(await x(h(d(l)),async u=>u.response.status===404?{name:"NotFoundError",message:(await u.response.json()).message}:u),u=>u.json())};var Pt=(e,r)=>{let t=new FormData;return t.append("data",e),t.append("metadata",JSON.stringify({app:"Gyazo",title:e.name})),GM_fetch(https://gif.gyazo.com/${r?.teams?"teams":"gif"}/upload,{method:"POST",body:t,credentials:"include",headers:{Origin:"https://gyazo.com","sec-fetch-site":"same-site"},referrer:"https://gyazo.com/"})};var be="",It=!1,Ne=new Map,St=async(e,r,t,o)=>{let n=Ne.get(e.href);if(n)return n;if(e.hostname==="video.twimg.com"||${e}.endsWith(".svg")){let i=await GM_fetch(e);if(!i.ok)return;let f=i.headers.get("content-type")?.split?.(";")?.[0]??${e}.endsWith(".mp4")?"video/mp4":"video/webm",l=new File([await i.blob()],o||${r},{type:f});if(f==="video/mp4"){let C=await Pt(l);if(C.ok){let D=new URL(await C.text());return Ne.set(e.href,D),D}}let u=await Mt(l,t);if(E(u))throw Error(v(u).name);let A=new URL(I(u).embedUrl);return Ne.set(e.href,A),A}if(e.hostname!=="pbs.twimg.com"||!e.pathname.startsWith("/media"))return;if(It){if(!be)return}else{let i=await xt();if(It=!0,E(i)){alert("You haven't logged in Gyazo yet, so you can only upload images to scrapbox.io.");return}if(be=I(i)||"",!be){alert("You haven't connect Gyazo to scrapbox.io yet.");return}}let s=await GM_fetch(e);if(!s.ok)return;let a=await nt(await s.blob(),{accessToken:be,refererURL:r,description:o});if(E(a))throw Error(v(a).name);let p=new URL(I(a).permalink_url);return Ne.set(e.href,p),p};var Bt=[["&","&"],["<","<"],[">",">"],['"',"""],["'","'"]],$r=Object.fromEntries([...Bt.map(([e,r])=>[r,e]),["'","'"],[" "," "]]),jr=new Map(Bt),zy=new RegExp([${...jr.keys().join("")}],"g");var Dr={entityList:$r},Vr=1114111,Wr=/&#([0-9]+);/g,qr=/&#x(\p{AHex}+);/gu,Ct=new WeakMap;function He(e,r={}){let{entityList:t}={...Dr,...r},o=Ct.get(t);return o||(o=new RegExp((${Object.keys(t).sort((n,s)=>s.length-n.length).join("|")}),"g"),Ct.set(t,o)),e.replaceAll(o,n=>t[n]).replaceAll(Wr,(n,s)=>vt(s,10)).replaceAll(qr,(n,s)=>vt(s,16))}function vt(e,r){let t=parseInt(e,r);return t>Vr?"�":String.fromCodePoint(t)}var Le=e=>{let r={name:e.user.name,screenName:e.user.screen_name},t=new Date(e.created_at),o=[...e.entities.hashtags.map(a=>({type:"hashtag",...a})),...e.entities.symbols.map(a=>({type:"symbol",...a})),...e.entities.user_mentions.map(a=>({type:"mention",name:a.name,screenName:a.screen_name,indices:a.indices})),...e.entities.urls.map(a=>{let p={type:"url",indices:a.indices,url:new URL(a.expanded_url)};if(e.card&&e.card?.url===a.url){let{description:i,title:f}=e.card.binding_values,l="STRING";i?.type===l&&(p.description=i.string_value),f?.type===l&&(p.title=f.string_value)}return p}),...e.entities.media?.map?.(a=>({type:"media",indices:a.indices,media:e.mediaDetails?.flatMap?.(p=>p.url===a.url?[{type:p.type,url:new URL(p.video_info?.variants?.sort?.((i,f)=>(f.bitrate??0)-(i.bitrate??0))?.[0].url??p.media_url_https)}]:[])??[]}))??[]].sort((a,p)=>a.indices[0]-p.indices[0]),n=[];{let a=0,p=e.text;for(let{indices:i,...f}of o){let l=[...p].slice(0,i[0]-a).join("");n.push({type:"plain",text:He(l)}),n.push(f),p=[...p].slice(i[1]-a).join(""),a=i[1]}p&&n.push({type:"plain",text:He(p)})}let s={id:e.id_str,content:n,author:r,posted:t,replyCount:"reply_count"in e?e.reply_count:e.conversation_count};return e.self_thread&&(s.rootId=e.self_thread.id_str),e.in_reply_to_status_id_str&&(s.replyId=e.in_reply_to_status_id_str),e.parent&&(s.replyTo=Le(e.parent)),e.quoted_tweet&&(s.quote=Le(e.quoted_tweet)),s};var Kr=["landing","product","enterprise","pricing","try-enterprise","contact","terms","privacy","jp-commercial-act","support","case","features","business","auth","login","logout","oauth2","_","api","app.html","assets","file","files","billing","billings","config","feed","index","io","new","opensearch","project","projects","search","setting","settings","setup-profile","slide","socket.io","stream","user","users"],Ue=(e=scrapbox.Project.name,r=location.host)=>t=>{if(t.host!==r)return t;let[,o,n]=t.pathname.match(/^\/([\w\d][\w\d-]{0,22}[\w\d])(?:\/?|\/(.+))$/)??[];return!o||Kr.includes(o)?t:n?o===e?${decodeURIComponent(n)}:/${o}/${decodeURIComponent(n)}:/${o}};var Ht=(e=zr)=>r=>{let[,t]=r.href.match(/^https:\/\/(?:www\.|mobile\.|m\.|)(?:twitter|x)\.com\/[A-Za-z0-9_]*\/(?:status|statuses)\/(\d+)/)??[];return t?(async()=>{let o=await(rt(t)??Tt(r.href));if(E(o))throw v(o);let n=I(o);return e("images"in n?{...n,id:t}:n,r)})():r},zr=async e=>{if("images"in e)return ee(e);let{quote:r,replyTo:t,...o}=Le(e);return[...t?[...(await ee(t)).split( ).map(n=> > ${n}),...t.quote?(await ee(t.quote)).split(
).map(n=> > ${n}):[]]:[],...(await ee(o)).split(
).map(n=>> ${n}),...r?(await ee(r)).split(
).map(n=>> > ${n}):[]].join(
)?.map?.(n=>> ${$e(n)})??["> [/ no description provided]"],...e.images.length>0?[> ${e.images.map(n=>[${n}])}]:[]].join(
);let t=e.content,o=e.author.screenName;return[@${$e(o)} ${r},...(await Promise.all(t.map(async n=>{switch(n.type){case"plain":return n.text;case"hashtag":return #${n.text} ;case"symbol":return #$${n.text} ;case"mention":return@${n.screenName};case"media":{let s=[],a=1;for(;a<n.media.length;a+=2)s.push([${await Ge(n.mediaa-1,r)}] [${await Ge(n.mediaa,r)}]);return a===n.media.length&&s.push([${await Ge(n.mediaa-1,r)}]), ${s.join(`
`)}
}case"url":return${Ue()(n.url)} }}))).join("").split(
)].join(
)},Fe="",Yr=async()=>{if(Fe)return Fe;let e=await gt(scrapbox.Project.name);if(E(e))throw new Error(v(e).name);return Fe=I(e).id,Fe},Ge=async(e,r)=>await St(e.url,r,await Yr(),"")??e.url,$e=e=>e.replace(/\b/gm,"").replace(/[\s\r\n\u2028\u2029]+/gm," ").replace(/\s*[[\]]\s*/g," ").trim();var Gt=e=>window.GM_fetch?.(https://t.co/${e})?.then?.(r=>W(K(r),async t=>{let o=new DOMParser().parseFromString(await t.text(),"text/html");try{return new URL(o.title)}catch(n){if(n instanceof TypeError)return;throw n}}));var $t=e=>{let r=window.GM_fetch;if("bit.ly","amzn.to","amzn.asia","goo.gl","s.nikkei.com","apple.co","nico.ms","w.wiki".includes(e.hostname)&&r)return r(e).then(o=>o.ok?new URL(o.url):e);if(e.hostname!=="t.co")return e;let t=Gt(e.pathname.slice(1));return t?t.then(o=>Pe(o,()=>e,n=>n??e)):e};var jt=e=>{if(!e.pathname.startsWith("/wiki/"))return e;if(!/^\w+\.wikipedia\.org$/.test(e.hostname)){let,n=e.hostname.match(/^(\w+)\.m\.wikipedia\.org$/)??[];if(!n)return e;e.hostname=${n}.wikipedia.org}let r=decodeURIComponent(e.pathname.slice(6)),t=e.hash?decodeURIComponent(e.hash.slice(1)):"",o=${e.origin}/wiki/${r};return t?[${t} | ${r} - Wikipedia ${o}#${t}]:[${r} - Wikipedia ${o}]};var Dt=e=>{if(e.hostname!=="www.wikiwand.com")return e;let,r,t=e.pathname.match(/^\/(^\/+)\/(^\/+)/)??[];return!r||!t||(e.hostname=${r}.wikipedia.org,e.pathname=/wiki/${t},e.hash=e.hash.startsWith("#/")?#${e.hash.slice(2)}:e.hash),e};var je=e=>{if(!e.hostname.startsWith("www.google."))return e;let r=e.searchParams.get("url");return r?new URL(decodeURIComponent(r)):e};var Vt=/charset=(^;+)/,Wt=e=>window.GM_fetch?.(${e})?.then?.(r=>W(K(r),async t=>{let o=t.headers.get("content-type")?.match?.(Vt)?.1??await Xr(t.clone());return new TextDecoder(o).decode(await t.arrayBuffer())})),Xr=async e=>{let r=new DOMParser().parseFromString(await e.text(),"text/html");return r.querySelector("metacharset")?.getAttribute?.("charset")??r.querySelector('metahttp-equiv="content-type"')?.getAttribute?.("content")?.match?.(Vt)?.1??"utf-8"};var qt=(e=Jr)=>async r=>e(await Qr(r),r),Jr=(e,r)=>{let t=(M(e)?e:e.title).replace(/\s/g," ").replaceAll("","[").replaceAll("","]");return t?[${r.hash?${decodeURIComponent(r.hash.slice(1))} | :""}${t} ${r}]:${r}},Qr=async e=>{let r=Wt(e);if(!r){let o=await ht(e);if(E(o))throw v(o);return I(o)}let t=await r;if(E(t))throw v(t);return new DOMParser().parseFromString(I(t),"text/html")};var Kt=e=>{if(!/^(?:www\.)?amazon(?:\.co|com)?\.(?:au|br|ca|fr|de|in|it|jp|mx|nl|sg|es|tr|ae|uk|cn)$/.test(e.hostname))return e;let,r=e.pathname.match(/\/dp\/(\w\d+)/)??e.pathname.match(/\/gp\/product\/(\w\d+)/)??e.pathname.match(/\/exec\/obidos\/asin\/(\w\d+)/)??e.pathname.match(/\/o\/ASIN\/(\w\d+)/)??[];return r&&(e.hash="",e.search="",e.pathname=/dp/${r}),e};var zt=e=>{if(!/(?:0-9a-z-\.)?gyazo\.com/.test(e.hostname))return e;let,r=e.pathname.match(/^\/(0-9a-f{32})(?:\/raw)?$/)??[];return r?[https://gyazo.com/${r}]:e};var Yt=(e,...r)=>{if(e instanceof URL)return Ae(new URL(e),...r);let t=0,o=0,n=0,s=!1,a=e.split(/(https?:\/\/\S+)/g).map(l=>{if(!/^https?:\/\/\S+$/.test(l))return l;t++;try{let u=Ae(new URL(l),...r);return M(u)?(o++,u):(s=!0,u,l)}catch(u){return console.error(u),n++,l}});if(!s)return a.join("");let{render:p,dispose:i}=Ke(),f=()=>p({type:"spinner"},{type:"text",text:URL: ${o}/${t} converted, ${n} failed});return f(),Promise.all(a.map(async l=>{if(M(l))return l;try{let u=await l0;return o++,u}catch(u){return console.error(u),n++,l1}finally{f()}})).then(l=>(p({type:"check-circle"},{type:"text",text:URL: ${o}/${t} converted, ${n} failed}),l.join(""))).finally(()=>{setTimeout(i,1e3)})};var Zr=je,$t,je,Dt,Kt,Ue(),zt,Ht(),jt,qt();scrapbox.PopupMenu.addButton({title:e=>/https?:\/\/\S+/.test(e)?"URL":"",onClick:e=>{let r=Yt(e,...Zr);if(typeof r=="string")return e===r?void 0:r;r.then(t=>{if(e!==t)return qe(t)})}}); code:credit.js
import{insertText}from"/api/code/customize/scrapbox-insert-text/script.js";(function(){"use strict";const e=document.createElement("style");e.textContent=.credits-popup-ui{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:#fff;color:#1B1B1B;padding:20px;border-radius:0;border:1px solid #D2D5DA;box-shadow:0 2px 8px rgba(0,0,0,0.08);z-index:9999;font-size:13px;font-family:'Inter','Noto Sans JP',sans-serif;font-weight:400;letter-spacing:.03em;width:650px;max-height:85vh;overflow-y:auto}.credits-popup-ui h3{font-size:14px;font-weight:500;margin:0 0 16px 0;color:#1B1B1B}.credits-popup-ui label{font-size:11px;color:#1B1B1B;font-weight:400;display:flex;flex-direction:column;gap:4px;margin-bottom:12px}.credits-popup-ui textarea{background:#fff;color:#1B1B1B;border:1px solid #D2D5DA;border-radius:0;padding:8px;width:100%;font-size:11px!important;line-height:1.8em!important;font-family:'Noto Sans JP','Inter',sans-serif;font-weight:400;letter-spacing:.03em;resize:vertical;min-height:180px}.credits-popup-ui textarea:focus{outline:none;border-color:#1F75BC}.credits-popup-ui textarea#creditsPreview{background:#f8f9fa;border-color:#dee2e6}.credits-popup-ui .option-group{margin-bottom:16px}.credits-popup-ui .option-label{font-size:11px;color:#1B1B1B;font-weight:400;margin-bottom:6px;display:block}.credits-popup-ui .option-buttons{display:flex;gap:0;border:1px solid #D2D5DA}.credits-popup-ui .option-btn{background:#fff;color:#1B1B1B;border:none;border-right:1px solid #D2D5DA;padding:8px 12px;cursor:pointer;font-size:12px;font-family:'Inter','Noto Sans JP',sans-serif;font-weight:400;letter-spacing:.03em;flex:1;text-align:center;}.credits-popup-ui .option-btn:last-child{border-right:none}.credits-popup-ui .option-btn:hover{background:#f8f9fa}.credits-popup-ui .option-btn.active{background:#1F75BC;color:#fff}.credits-popup-ui .option-btn.active:hover{background:#0056b3}.credits-popup-ui .button-group{display:flex;gap:8px;justify-content:flex-end;padding-top:12px;border-top:1px solid #D2D5DA}.credits-popup-ui button.action-btn{background:transparent;color:#1B1B1B;border:none;border-radius:0;padding:8px 16px;cursor:pointer;font-size:11px;font-family:'Inter','Noto Sans JP',sans-serif;font-weight:400;letter-spacing:.03em;text-transform:uppercase}.credits-popup-ui button.action-btn:hover{text-decoration:underline}.credits-popup-ui button.primary{background:#1F75BC;color:#fff}.credits-popup-ui button.primary:hover{background:#0056b3;text-decoration:none}.credits-hint{font-size:11px;color:#a0a0a0;margin-top:-8px;margin-bottom:12px};document.head.appendChild(e);const t='WIT STUDIO','STUDIO','スタジオ','プロダクション','PRODUCTION','リングス','戯画プロダクション','D-COLORS','グレーン','青写真','IKIF+','旭プロダクション','エディッツ','MAPPA','ufotable','A-1 Pictures','CloverWorks','Bones','TRIGGER','Kyoto Animation','Production I.G','MADHOUSE','シャフト','J.C.STAFF','david production','SILVER LINK','LIDENFILMS','Lerche','Doga Kobo','動画工房','株式会社','有限会社','Inc.','Co.,Ltd.','Ltd.','Bamboo','グラフィニカ','三嶋編集室','MONACA','FLAT STUDIO','ニトロプラス','東映アニメーション';function n(e){const n=e.trim();if(!n||/^-\-\/\s+$/.test(n))return!0;for(const e of t)if(n.includes(e))return!0;return/^((^))+))$/.test(n)}function r(e){const t=e.trim();return!(!t||/^-\-\/\s+$/.test(t))&&(!n(t)&&(!/^((^))+))$/.test(t)&&!!/\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF/.test(t)||/^a-zA-Z+$/.test(t)||/^a-zA-Zぁ-んァ-ヶー+$/.test(t)))}function i(e,t,n,i){if(!e.trim())return'';const a=e.split('\n'),o={};let s=null,c=!1;for(let e=0;e<a.length;e++){let l=ae.trim();if(l&&!/^-\-+$/.test(l)){if('CAST'===l.toUpperCase()||'キャスト'===l){c=!0;continue}if(c){const t=l;if(e+1<a.length){const n=ae+1.trim();if(n&&!n.includes(':')&&!n.includes(':')){s=t,os||(os=[]),os.push(n),e++;continue}}}if(l.includes('/')){const e=l.split('/');for(const t of e){const e=t.trim();if(e.includes(':')||e.includes(':')){const t=e.includes(':')?':':':',a=e.split(t),c=a0.trim(),l=a.slice(1).join(':').trim();if(s=c,os||(os=[]),l){const e=l.split(/、,\/・/).map(e=>e.trim()).filter(e=>e);os.push(...e)}}}}else if(l.includes(':')||l.includes(':')){const e=l.includes(':')?':':':',t=l.split(e),n=t0.trim(),r=t.slice(1).join(':').trim();if(s=n,os||(os=[]),r){const e=r.split(/、,\/・/).map(e=>e.trim()).filter(e=>e);os.push(...e)}}else if(!c){if(e+1<a.length){const t=ae+1.trim();if(t&&!t.includes(':')&&!t.includes(':')&&!t.includes('/')){s=l,os||(os=[]);const n=t.split(/、,\/・/).map(e=>e.trim()).filter(e=>e);os.push(...n),e++;continue}}if(s){const e=l.split(/、,\/・/).map(e=>e.trim()).filter(e=>e);os.push(...e)}}}}let l='';const d=Object.entries(o);for(let e=0;e<d.length;e++){consta,o=de,s=o.map(e=>{const t=e.match(/^(.+?)(((.+)))$/);if(t){const e=t1.trim(),n=t2;return r(e)?[${e}]${n}:e}return r(e)?[${e}]:e});l+='singleline'===t?${a}${n}${s.join(i)}${e<d.length-1?'/':''}:${a}${n}${s.join(i)}\n}return'singleline'===t?l:l.trim()}scrapbox.PageMenu.addMenu({title:"クレジット整形",image:"https://cdnjs.cloudflare.com/ajax/libs/twemoji/12.0.4/svg/1f3ac.svg",onClick:a}),document.addEventListener("keydown",e=>{e.ctrlKey&&e.shiftKey&&"c"===e.key.toLowerCase()&&(e.preventDefault(),a())});function a(){if(document.querySelector(".credits-popup-ui"))return;const e=document.createElement("div");e.className="credits-popup-ui",e.innerHTML=<h3>アニメクレジット整形</h3><label>クレジット情報:<textarea id="creditsInput" placeholder="クレジット情報を貼り付けてください..."></textarea></label><p class="credits-hint">複数の形式に対応しています(/区切り、改行、など)</p><div class="option-group"><label class="option-label">出力形式:</label><div class="option-buttons"><button class="option-btn active" data-format="multiline">役職ごとに改行</button><button class="option-btn" data-format="singleline">1行にまとめる</button></div></div><div class="option-group"><label class="option-label">役職と人名の区切り:</label><div class="option-buttons"><button class="option-btn active" data-separator=":">全角コロン</button><button class="option-btn" data-separator=": ">: +半角</button><button class="option-btn" data-separator=":">半角コロン</button></div></div><div class="option-group"><label class="option-label">人名同士の区切り:</label><div class="option-buttons"><button class="option-btn active" data-name-sep=" / "> / </button><button class="option-btn" data-name-sep="・">・</button><button class="option-btn" data-name-sep="、">、</button></div></div><label>プレビュー:<textarea id="creditsPreview" placeholder="整形結果がここに表示されます..." readonly></textarea></label><div class="button-group"><button class="action-btn" id="cancelBtn">キャンセル</button><button class="action-btn primary" id="insertBtn">整形して挿入</button></div>,document.body.appendChild(e);const t=e.querySelector("#creditsInput"),n=e.querySelector("#creditsPreview"),r=e.querySelector("#insertBtn"),a=e.querySelector("#cancelBtn");function o(){const r=t.value,a=e.querySelector('.option-btn.activedata-format')?.dataset.format||'multiline',o=e.querySelector('.option-btn.activedata-separator')?.dataset.separator||':',s=e.querySelector('.option-btn.activedata-name-sep')?.dataset.nameSep||' / ';if(!r.trim())return void(n.value='');const c=i(r,a,o,s);n.value=c}e.querySelectorAll('.option-btn').forEach(e=>{e.addEventListener('click',e=>{const t=e.target.closest('.option-buttons');t.querySelectorAll('.option-btn').forEach(e=>e.classList.remove('active')),e.target.classList.add('active'),o()})}),t.addEventListener('input',o),r.onclick=function(){const e=n.value;e.trim()&&(insertText({text:e}),s())},a.onclick=s,e.addEventListener("keydown",e=>{"Escape"===e.key&&(e.preventDefault(),s()),e.ctrlKey&&"Enter"===e.key&&(e.preventDefault(),r.onclick())}),t.focus();function s(){e.remove()}}})();