Greasy Fork is available in English.
在磁力链接旁添加复选框,支持按季批量选择,简约玻璃风UI
当前为
// ==UserScript==
// @name 磁力链接批量选择工具(Fluent Design 玻璃UI)
// @namespace http://tampermonkey.net/
// @version 3.0
// @description 在磁力链接旁添加复选框,支持按季批量选择,简约玻璃风UI
// @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;
// 🌟 创建 Fluent Design 玻璃风工具栏
let toolbar = document.createElement("div");
toolbar.id = "magnet-toolbar";
toolbar.style.position = "fixed";
toolbar.style.bottom = "20px";
toolbar.style.right = "20px";
toolbar.style.background = "rgba(255, 255, 255, 0.2)";
toolbar.style.backdropFilter = "blur(10px)"; // Fluent Design 关键:背景模糊
toolbar.style.border = "1px solid rgba(255, 255, 255, 0.3)";
toolbar.style.padding = "12px";
toolbar.style.borderRadius = "12px";
toolbar.style.boxShadow = "0 4px 12px rgba(0, 0, 0, 0.2)";
toolbar.style.zIndex = "9999";
toolbar.style.fontFamily = "Segoe UI, Arial, sans-serif";
toolbar.style.display = "flex";
toolbar.style.gap = "10px";
let style = document.createElement("style");
style.innerHTML = `
.fluent-btn {
color: white;
border: none;
padding: 10px 15px;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
transition: all 0.3s ease;
}
.fluent-btn:hover {
transform: scale(1.05);
box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}
.fluent-green { background: rgba(76, 175, 80, 0.8); }
.fluent-blue { background: rgba(33, 150, 243, 0.8); }
`;
document.head.appendChild(style);
toolbar.innerHTML = `
<button id="copy-selected" class="fluent-btn fluent-green">📋 复制选中</button>
<button id="open-selected" class="fluent-btn fluent-blue">🚀 打开选中</button>
`;
document.body.appendChild(toolbar);
// 🌟 遍历所有磁力链接,按标题分类
let lastTitle = null;
links.forEach(link => {
let title = getNearestTitle(link); // 获取该磁力链接的标题
if (title && title !== lastTitle) {
// 检查是否已添加过全选框
if (!title.querySelector(".season-checkbox")) {
// 标题右侧添加“全选”复选框
let titleCheckbox = document.createElement("input");
titleCheckbox.type = "checkbox";
titleCheckbox.classList.add("season-checkbox");
titleCheckbox.style.marginLeft = "10px";
titleCheckbox.style.transform = "scale(1.5)"; // 让它比普通复选框大 1.5 倍
titleCheckbox.dataset.group = title.innerText.trim();
title.appendChild(titleCheckbox); // 插入到标题右侧
titleCheckbox.addEventListener("change", function() {
let group = this.dataset.group;
document.querySelectorAll(`a[href^="magnet:?"][data-group="${group}"] + input`).forEach(cb => {
cb.checked = this.checked;
});
});
}
lastTitle = title;
}
// 磁力链接旁添加复选框,并标记所属分组
let checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.style.marginLeft = "5px";
checkbox.dataset.group = lastTitle ? lastTitle.innerText.trim() : "";
link.setAttribute("data-group", checkbox.dataset.group);
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("未选择任何磁力链接!");
}
});
}
function getNearestTitle(element) {
let node = element;
while (node && node !== document.body) {
if (node.previousElementSibling && /^h[1-6]$/i.test(node.previousElementSibling.tagName)) {
return node.previousElementSibling;
}
node = node.parentElement;
}
return null;
}
// 监听页面变化,动态添加复选框(适用于 AJAX 加载)
let observer = new MutationObserver(addCheckboxes);
observer.observe(document.body, { childList: true, subtree: true });
// 初次运行
addCheckboxes();
})();