選択したGyazoのOCRテキストをコピーするUserScript
Popup Menu ver.
popupMenu.jsscrapbox.PopupMenu.addButton({
title: (text) => /https:\/\/(?:thumb\.|i\.)?gyazo\.com\/[a-z0-9]+/.test(text)
? globalThis.GM_fetch
? "copy Gyazo OCR"
: "open Gyazo"
: "",
onClick: async (text) => {
const id = text.match(/https:\/\/(?:thumb\.|i\.)?gyazo\.com\/([a-z0-9]+)/)?.[1];
if (!id) return;
if (!globalThis.GM_fetch) {
window.open(`https://gyazo.com/${id}`);
return;
}
const res = await GM_fetch(`https://gyazo.com/${id}.json`);
const ocr = (await res.json()).metadata?.ocr?.description;
if (!ocr) return;
try {
await navigator.clipboard.writeText(ocr);
} catch(e) {
console.error(e);
alert(`${e.name} ${e.message}`);
}
},
});
#2023-02-24 05:18:20 tamperMonkeyがないときは、gyazoページを開くようにした