Skip to content

Instantly share code, notes, and snippets.

@nicholastay
Created June 27, 2023 08:58
Show Gist options
  • Save nicholastay/25a05cd4331d016158164c2dac9c0cb8 to your computer and use it in GitHub Desktop.
Save nicholastay/25a05cd4331d016158164c2dac9c0cb8 to your computer and use it in GitHub Desktop.
Copy all visible magnets on nyaa
// ==UserScript==
// @name nyaa copy all magnets
// @namespace nick.tay.blue
// @match https://nyaa.si/*
// @grant none
// @version 0.1.0
// @author Nicholas Tay <nick@windblume.net>
// @description Copy all visible magnet links from results page
// ==/UserScript==
;(function() {
const elems = document.getElementsByClassName("table-responsive");
if (elems.length < 1)
return;
const table = elems[0];
window.copyAllMagnets = function() {
let links = [];
for (const a of document.querySelectorAll("tbody td a")) {
if (!a.href.startsWith("magnet:"))
continue;
links.push(a.href);
}
navigator.clipboard.writeText(links.join("\n"));
};
const html = `<button style="float: right; margin-bottom: 4px" onclick="window.copyAllMagnets();">Copy Magnets</button>`;
table.insertAdjacentHTML("afterbegin", html);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment