popup
code:script.ts
import "../unlink_Popup_menu/script.ts";
code:script.ts
import type { Scrapbox } from "../scrapbox-jp%2Ftypes/userscript.ts";
declare const scrapbox: Scrapbox;
// 選択範囲に下線を引く
scrapbox.PopupMenu.addButton({
title: '\uf0cd',
onClick: text => [_ ${text}]
});
code:script.ts
scrapbox.PopupMenu.addButton({
title: "\uf698",
onClick: text => [$ ${text}]
});
code:script.ts
import "../長いタイトルを刻むページを簡単に作れるUserScript/main.ts";
code:script.ts
import { makeNewPage } from "../custom-new-page/mod.ts";
import {
newPageHook,
splittedLinkHook,
taskLineHook,
} from "../for-custom-new-page/mod.ts";
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;
},
});
末尾が拡張子で終わっていない画像URLをscrapboxに埋め込む
2023-02-06 05:36:43
URLを含むときのみ実行する
URLだけを画像記法に直す
code:script.ts
{
/** 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;
},
});
}
code:script.ts
//import '/api/code/scrapboxlab/いい感じにリンクするomakase-links/script.js';
2020-10-01 13:00:26 全然使わないので外した
code:script.ts
// 選択された文字列をScrapboxプロジェクト内で検索する
// Scapbox検索ボックスを使ったときと同じ結果ページを開く
scrapbox.PopupMenu.addButton({
title: "S",
onClick: (text) => {
window.open(https://scrapbox.io/${scrapbox.Project.name}/search/page?q=${text});
return undefined;
},
});
code:script.ts
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;
}
});
2023-02-06 05:56:07 アイコンを変えた
code:script.ts
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;
}
});
選択範囲を検索するように変えた
code:script.ts
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;
}
});
code:script.ts
// インライン引用
scrapbox.PopupMenu.addButton({
title: '\uf10e',
onClick: text => [" ${text}]
});
indentを保持するように書き換えたい
2021-05-26 15:15:50 使わないので消した
code:script.ts.disabled(ts)
// 選択範囲を引用にする
scrapbox.PopupMenu.addButton({
title: '\uf101',
onClick: text => text.split(/\n/).map(line => > ${line}).join('\n')
});
code:script.ts
// 拡張記法
// 選択した文字列にマーカー
scrapbox.PopupMenu.addButton({
title: '🖍',
onClick: text => [[${text}]]
});
code:script.ts
import '../選択範囲をMarkdown記法に変換してclip_boardにcopyするPopupMenu/script.js';
code:script.ts
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;
}
});
code:script.ts
import {
convert,
convertGyazoURL,
convertScrapboxURL,
expandShortURL,
formatTweet,
formatURL,
formatWikipedia,
type 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からいらないparametersを消す code:script.ts
(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");
const result = new URL(url);
// URL.searchParamsはsetterがないのでresetできない。代わりにURL.search経由でresetする
result.search = "";
if (dt) result.searchParams.append("dt", dt);
if (result.pathname.startsWith("/transit/route/")) {
if (tm) result.searchParams.append("tm", tm);
if (sr) result.searchParams.append("sr", sr);
}
return result;
},
code:script.ts
(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;
},
code:script.ts
(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;
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+)/) ?? [];
start && end ? L${start}-${end}/ : start ? L${start}/ : ""
},
code:script.ts
// 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;
},
});
code:script.ts
import '../複数行に打ち消し線を引くPopup Menu@0.3.0/script.js';
code:script.ts
import "../replace_text_UserScript再実装版/script.js";
code:script.ts
import { setup } from "../複数のリンクをまとめて置換するUserScript/example.ts";
code:script.ts
import "../一旦改行を消して句点で改行し直すPopupMenu/script.js";
code:script.ts
import "../選択したGyazoのOCRテキストをコピーするUserScript/popupMenu.js";
code:script.ts
import "../選択したGyazo画像のtrimmingページを開くPopup_Menu/script.js";
code:script.ts
import "../Scrapbox記法をTeX記法に変換するPopupMenu/script.ts";
code: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"),
});*/
}
併用するstyle
code:style.css
@import '../popupmenuのbuttonを非表示にする/style.css';
code:style.css
@import '../PopupMenuを徹底的にアイコンにする/style.css';
なぜかhttpRegExpがdeno checkでmodule can't be parsed errorを吐くので書き換えた
01:03:03 Typescriptに書き換え & middlewares追加
いくつかrefactoring & アイコン変更