🏠 Home 

Nyaa Batch Copy

Batch copy magnet links | 批量复制磁力链接


Install this script?
// ==UserScript==
// @name         Nyaa Batch Copy
// @license      cc
// @namespace    https://form.yejia995.top
// @version      0.2
// @description  Batch copy magnet links | 批量复制磁力链接
// @author       Yejia995, luminisward
// @match        https://*.nyaa.si/*
// @grant        none
// @require      https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js
// ==/UserScript==
(function() {
"use strict";
var $ = window.jQuery;
function insertCheckbox() {
var headRow = $(".table thead tr");
headRow.prepend(
$("<th>").append(
$('<input type="checkbox" id="checkall" />')
.attr("checked", true)
.css("display", "block")
.css("margin", "0 auto")
.change(function() {
$("tbody input").prop("checked", this.checked);
})
)
);
var bodyRows = $(".table tbody tr");
bodyRows.each(function() {
$(this).prepend(
$("<td>").append($('<input type="checkbox" />').attr("checked", true).css("display", "block").css("margin", "0 auto"))
);
});
}
function getCheckedList() {
var checkboxList = $("tbody input");
return $.map(checkboxList, x => x.checked);
}
function getMagnetLinks() {
var bodyRows = $("tbody a");
var links = $.map(bodyRows, x => x.href);
return links.filter(link => link.includes("magnet:"));
}
function insertCopyButton() {
var navBar = $("ul.nav");
var button = document.createElement("li");
var a = document.createElement("a");
$(a)
.attr("href", "")
.text("Copy Link")
.attr("id", "copyMagnet")
.attr("title", "Copy selected links")
.click(e => {
e.preventDefault();
});
button.append(a);
navBar[0].append(button);
}
function showNotification(message) {
var notification = $("<div>")
.text(message)
.css({
position: "fixed",
top: "90%",
left: "50%",
transform: "translate(-50%, -50%)",
background: "rgba(0, 0, 0, 0.8)",
color: "white",
padding: "10px",
borderRadius: "5px",
zIndex: 9999
})
.appendTo($("body"));
setTimeout(function() {
notification.fadeOut(500, function() {
$(this).remove();
});
}, 3000);
}
insertCopyButton();
insertCheckbox();
// eslint-disable-next-line no-undef
new ClipboardJS("#copyMagnet", {
text: function() {
var links = getMagnetLinks();
var checkedList = getCheckedList();
links = links.filter(function(val, i) {
return checkedList[i];
});
showNotification("Copied " + links.length + " magnet links to clipboard.");
return links.join("\n");
}
});
})();