Greasy Fork is available in English.
在磁力链接旁添加复选框,支持批量复制或打开
当前为
// ==UserScript==
// @name 磁力链接批量选择工具
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 在磁力链接旁添加复选框,支持批量复制或打开
// @author 你的名字
// @match *://*/*
// @grant GM_setClipboard
// ==/UserScript==
(function() {
'use strict';
function addCheckboxes() {
// 获取所有磁力链接
let links = document.querySelectorAll('a[href^="magnet:?"]');
if (links.length === 0) return;
// 避免重复添加
if (document.getElementById("magnet-toolbar")) return;
// 创建工具栏
let toolbar = document.createElement("div");
toolbar.id = "magnet-toolbar";
toolbar.style.position = "fixed";
toolbar.style.bottom = "10px";
toolbar.style.right = "10px";
toolbar.style.background = "#fff";
toolbar.style.border = "1px solid #ddd";
toolbar.style.padding = "10px";
toolbar.style.boxShadow = "0 0 10px rgba(0,0,0,0.2)";
toolbar.style.zIndex = "9999";
toolbar.innerHTML = `
<button id="copy-selected" style="margin-right:5px;">📋 复制选中</button>
<button id="open-selected">🚀 打开选中</button>
`;
document.body.appendChild(toolbar);
// 在磁力链接旁添加复选框
links.forEach(link => {
let checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.style.marginLeft = "5px";
link.after(checkbox);
});
// 复制选中的磁力链接
document.getElementById("copy-selected").addEventListener("click", () => {
let selectedLinks = [...document.querySelectorAll('a[href^="magnet:?"] + input:checked')]
.map(cb => cb.previousSibling.href)
.join("\n");
if (selectedLinks) {
GM_setClipboard(selectedLinks);
alert("已复制选中的磁力链接!");
} else {
alert("未选择任何磁力链接!");
}
});
// 打开选中的磁力链接
document.getElementById("open-selected").addEventListener("click", () => {
let selectedLinks = [...document.querySelectorAll('a[href^="magnet:?"] + input:checked')]
.map(cb => cb.previousSibling.href);
if (selectedLinks.length > 0) {
selectedLinks.forEach(link => window.open(link, "_blank"));
} else {
alert("未选择任何磁力链接!");
}
});
}
// 监听页面变化,动态添加复选框(适用于 AJAX 加载)
let observer = new MutationObserver(addCheckboxes);
observer.observe(document.body, { childList: true, subtree: true });
// 初次运行
addCheckboxes();
})();