import "../unlink_Popup_menu/script.ts"; import type { Scrapbox } from "../scrapbox-jp%2Ftypes/userscript.ts"; declare const scrapbox: Scrapbox; // 選択範囲に下線を引く scrapbox.PopupMenu.addButton({ title: '\uf0cd', onClick: text => `[_ ${text}]` }); scrapbox.PopupMenu.addButton({ title: "\uf698", onClick: text => `[$ ${text}]` }); import "../長いタイトルを刻むページを簡単に作れるUserScript/main.ts"; import { makeNewPage } from "../custom-new-page/mod.ts"; import { newPageHook, splittedLinkHook, taskLineHook, } from "../for-custom-new-page/mod.ts"; const hooks = [taskLineHook, newPageHook, splittedLinkHook]; scrapbox.PopupMenu.addButton({ title: (text) => { const hook = makeNewPage({ project: scrapbox.Project.name, mode: "noopen", hooks }); if (!hook || hook.hookName.includes("default")) return ""; if (hook.hookName.includes("task")) return "\uf0c4\uf46d"; if (hook.hookName.includes("split")) return "\uf0c4\uf595"; return "\uf0c4"; }, onClick: () => { const project = window.prompt("Create a new page at", scrapbox.Project.name); if (!project) return; makeNewPage({ project, mode: "noopen", hooks })?.(); return undefined; }, }); { /** from scrapbox-parser */ scrapbox.PopupMenu.addButton({ title: (text) => /(https?:\/\/[^\s]+)/g.test(text) ? "\uf03e" : "", onClick: (text) => { const newText = text.replace(/(https?:\/\/[^\s]+)/g, "[$1#.jpg]"); if (text === newText) return; return newText; }, }); } //import '/api/code/scrapboxlab/いい感じにリンクするomakase-links/script.js'; // 選択された文字列をScrapboxプロジェクト内で検索する // Scapbox検索ボックスを使ったときと同じ結果ページを開く scrapbox.PopupMenu.addButton({ title: "S", onClick: (text) => { window.open(`https://scrapbox.io/${scrapbox.Project.name}/search/page?q=${text}`); return undefined; }, }); scrapbox.PopupMenu.addButton({ title: '\uf1a0', onClick: text => { // 記法を解除する const keyword = text.split(/\n/) .map(line => line.replace(/\[(.*)\]/g,'$1')).join('\n'); window.open(`https://www.google.com/search?q=${encodeURIComponent(keyword)}`); return undefined; } }); scrapbox.PopupMenu.addButton({ title: "\uf1ab", onClick: text => { const isJapanese = (str: string) => [...str].some(char => char.charCodeAt(0) > 255); // 記法を解除する const keyword = text.split(/\n/) .map(line => line.replace(/\[(.*)\]/g,'$1')).join('\n').trim().replace(/\s+/g,'+'); if (isJapanese(keyword)) { window.open(`https://www.ldoceonline.com/search/japanese-english/direct/?q=${encodeURIComponent(keyword)}`); } else { window.open(`https://www.oxfordlearnersdictionaries.com/search/english/?q=${encodeURIComponent(keyword)}`); } return undefined; } }); scrapbox.PopupMenu.addButton({ title: '\uf002', onClick: text => { // 記法を解除する const keyword = text.split(/\n/) .map(line => line.replace(/\[(.*)\]/g,'$1')).join('\n'); window.open(`https://www.google.com/search?q=${encodeURIComponent(keyword)}+site:scrapbox.io`); return undefined; } }); // インライン引用 scrapbox.PopupMenu.addButton({ title: '\uf10e', onClick: text => `[" ${text}]` }); // 拡張記法 // 選択した文字列にマーカー scrapbox.PopupMenu.addButton({ title: '🖍', onClick: text => `[[${text}]]` }); import '../選択範囲をMarkdown記法に変換してclip_boardにcopyするPopupMenu/script.js'; scrapbox.PopupMenu.addButton({ title: text => /\$([^$]+)\$/.test(text) ? 'L' : '', onClick: text => { const result = text.split(/\n/) .map(line => line.replace(/\$([^$]+)\$/g,`[$ $1]`)).join('\n'); // テロメアが無駄に更新されるのを防ぐ if(text == result) return; return result; } }); import { convert, convertGyazoURL, convertScrapboxURL, expandShortURL, formatTweet, formatURL, formatWikipedia, Middleware, redirectGoogleSearch, redirectWikiwand, shortenAmazonURL, } from "../takker99%2Fscrapbox-url-customizer/mod.ts"; import { formatNiconico } from "../nicothumb2img/middleware.ts"; import { insertText } from "../scrapbox-userscript-std/dom.ts"; // 毎回functionsを作るのは無駄なので、globalに保持しておく const middlewares: Middleware[] = [ redirectGoogleSearch, expandShortURL, redirectGoogleSearch, redirectWikiwand, shortenAmazonURL, convertScrapboxURL(), convertGyazoURL, formatTweet(), formatWikipedia, (url) => { if (url.hostname !== "ekitan.com") return url; if (!/^\/transit\/(?:route|first|last)\//.test(url.pathname)) return url; const dt = url.searchParams.get("dt"); const tm = url.searchParams.get("tm"); const sr = url.searchParams.get("sr"); // URL.searchParamsはsetterがないのでresetできない。代わりにURL.search経由でresetする url.search = ""; if (dt) url.searchParams.append("dt", dt); if (url.pathname.startsWith("/transit/route/")) { if (tm) url.searchParams.append("tm", tm); if (sr) url.searchParams.append("sr", sr); } return url; }, (url) => { if (url.host !== location.host) return url; if (!url.pathname.startsWith("/api/code/")) return url; const path = encodeURIComponent(`${url.origin}${url.pathname}`); return `${url}`.endsWith(".svg") ? `[https://svg-hosting.vercel.app/api/svg?url=${path} ${url}]` : `${url}`.endsWith(".mlt") ? `[https://aa2svg.vercel.app/svg/${path}?width=1000 ${url}]` : url; }, (url) => { if (url.hostname === "raw.githubusercontent.com") { return `[https://code2svg.vercel.app/svg/${url.origin}${url.pathname}#.svg ${url}]`; } if (url.hostname !== "github.com") return url; const [user, repo, filepath] = url.pathname.match(/^\/([^\\]+)\/([^\\]+)\/blob\/(.+)$/)?.slice?.(1) ?? []; if (!user || !repo || !filepath) return url; const [, start, end] = url.hash.match(/L(\d+)-L(\d+)/) ?? url.hash.match(/L(\d+)/) ?? []; return `[https://code2svg.vercel.app/svg/${ start && end ? `L${start}-${end}/` : start ? `L${start}/` : "" }https://raw.githubusercontent.com/${user}/${repo}/${filepath}#.svg ${url}]`; }, // githubはそのまま返す (url) => url.hostname === "github.com" ? `${url}` : url, formatNiconico, formatURL(), ]; scrapbox.PopupMenu.addButton({ title: (text) => /https?:\/\/\S+/.test(text) ? "URL" : "", onClick: (text) => { const promise = convert(text, ...middlewares); if (typeof promise === "string") { // 文字列に違いがあるときのみ更新 return text === promise ? undefined : promise; } // 選択範囲に変換後の文字列を上書きする // 変換中に選択範囲が変わると、ずれた位置に挿入されるので注意 promise.then((converted) => { if (text === converted) return; return insertText(converted); }); return undefined; }, }); import '../複数行に打ち消し線を引くPopup Menu@0.3.0/script.js'; import "../replace_text_UserScript再実装版/script.js"; import { setup } from "../複数のリンクをまとめて置換するUserScript/example.ts"; setup(["takker", "takker-memex", "takker-private", "takker-books"]); import "../一旦改行を消して句点で改行し直すPopupMenu/script.js"; import "../選択したGyazoのOCRテキストをコピーするUserScript/popupMenu.js"; import "../選択したGyazo画像のtrimmingページを開くPopup_Menu/script.js"; import "../Scrapbox記法をTeX記法に変換するPopupMenu/script.ts"; import { startTalk } from "../scrapbox-keichobot/mod.ts"; import { textInput } from "../scrapbox-userscript-std/dom.ts"; if (!/mobile/i.test(navigator.userAgent)) { const talk = (text: string, mode?: "normal" | "empathy_writing" | "KPT" | "value_hypothesis") => { if (text.trim() === "") return undefined; startTalk({ mode }).then((result) => { if (!result) return; const { ask, visible, onExit } = result; const handleKeydown = (e: KeyboardEvent) => { if ( !visible() || e.key !== "Enter" || !e.ctrlKey || e.altKey || e.shiftKey ) return; e.preventDefault(); e.stopPropagation(); ask(); }; textInput()!.addEventListener("keydown", handleKeydown); onExit(() => textInput()!.removeEventListener("keydown", handleKeydown)); }); }; scrapbox.PopupMenu.addButton({ title: () => "🤖", onClick: (text) => talk(text), }); /* scrapbox.PopupMenu.addButton({ title: () => "🤖✍️", onClick: (text) => talk(text, "empathy_writing"), }); scrapbox.PopupMenu.addButton({ title: () => "🤖💡", onClick: (text) => talk(text, "value_hypothesis"), });*/ }