// ==UserScript== // @name JavDB - Copy all magnets // @namespace Violentmonkey Scripts // @match https://javdb.com/v/* // @grant none // @version 1.0 // @author Lukáš Kucharczyk // @description Adds a button to copy all magnet links at once. // @downloadURL https://git.kucharczyk.xyz/lukas/userscripts/raw/branch/main/javdb_copy_all_magnets.user.js // @supportURL https://git.kucharczyk.xyz/lukas/userscripts // ==/UserScript== /** * @param {string} type * @param {object} props * @param {...(string|HTMLElement)} children * @return {HTMLElement} */ function elt(type, props, ...children) { let dom = document.createElement(type); if (props) { Object.keys(props).forEach((key) => { if (key === "style") { Object.assign(dom.style, props[key]); } else if (key === "dataset") { Object.keys(props[key]).forEach((dataKey) => { dom.dataset[dataKey] = props[key][dataKey]; }); } else { dom[key] = props[key]; } }); } for (let child of children) { if (typeof child !== "string") dom.appendChild(child); else dom.appendChild(document.createTextNode(child)); } return dom; } function findElementsWithText(text, tagName = "*") { const elements = document.querySelectorAll(tagName); return Array.from(elements).filter((element) => element.textContent.includes(text) ); } const allMagnetButtons = findElementsWithText("Copy", "button"); let allMagnetLinks = allMagnetButtons.reduce((prevValue, currentButton) => { return prevValue + "\n" + currentButton.dataset.clipboardText; }, ""); let copyAllButton = elt( "div", { className: "item columns is-desktop", }, elt("div", { className: "magnet-name column is-four-fifths", }), elt( "div", { className: "buttons column", }, elt( "button", { type: "button", className: "button is-info copy-to-clipboard", dataset: { clipboardText: allMagnetLinks, }, }, "Copy all magnets" ) ) ); const magnetContainer = document.getElementById("magnets-content"); magnetContainer.prepend(copyAllButton);