// ==UserScript== // @name Copy to Scrapbox in Manga style // @namespace http://tampermonkey.net/ // @version 0.2 // @description Copy URLs of selected items from Gyazo to paste Scrapbox in Manga style // @author motoso // @match https://gyazo.com/captures // @match https://gyazo.com/search* // @run-at context-menu // @grant GM_setClipboard // @icon <$ICON$> // ==/UserScript== (function () { 'use strict'; function makeNthPageSpread(arr, n) { let pages = []; while (0 < arr.length) { pages.push(arr.splice(0, n)); } return pages; } const checkedCards = document.querySelectorAll(".card.checked"); let urls = []; for (const card of Array.from(checkedCards)) { const span = card.lastElementChild; const url = card.querySelector(".view-operation").href; urls.push(url); } // 下の方が先頭ページなので逆順にしてページに分割 const pages = makeNthPageSpread(urls.reverse(), 2); // 見開きに分割したら左とじに変換 const rightBindingPages = pages.map(p => p.reverse()) // 分割された配列を結合 GM_setClipboard(rightBindingPages.map(i => i .map((i) => `[[${i}]]`).join('')) // 見開きを結合 .join("\n")); // 見開きごとに改行 })();