// ==UserScript== // @name qB_WebUI_标签批量替换tracker // @name:en qB_WebUI_replace-trackers-with-tag // @namespace localhost // @version 1.0.1 // @author Kesa // @description 利用 qBitorrent WebUI 的 tag API 批量替换 Tracker // @description:en replace torrents tracker with tag in qBitorrent WebUI // @license MIT // @null ---------------------------- // @run-at document-end // @match http://127.0.0.1:8080/ // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.min.js // @downloadURL https://update.greasyfork.cloud/scripts/467682/qB_WebUI_%E6%A0%87%E7%AD%BE%E6%89%B9%E9%87%8F%E6%9B%BF%E6%8D%A2tracker.user.js // @updateURL https://update.greasyfork.cloud/scripts/467682/qB_WebUI_%E6%A0%87%E7%AD%BE%E6%89%B9%E9%87%8F%E6%9B%BF%E6%8D%A2tracker.meta.js // ==/UserScript== /** * 参考: https://greasyfork.org/zh-CN/scripts/391688-水水-qbittorrent-管理脚本-qq-群-189574683 * 感谢这位大佬, 本脚本是参考了一下这个大佬的脚本进行简化而来的 * ---------------- * 代码流程: * 1. 在 UI 界面开个 button 调出页面 * 2. 检测所有指定 tag 的种子 hash * 3. 将所有指定 hash 的种子的 tracker 改为 指定的 tracker */ // NOTE: 0. 顶层配置 const host = window.location.href; const baseURL = 'api/v2/torrents/'; const prevURL = host + baseURL; /**fetch GET 封装 * @param {*} route 路由 * @returns Promise */ async function getFetch(route) { try { const response = await fetch(prevURL + route); if (!response.ok) { throw new Error('请求失败'); } const data = await response.json(); return data; } catch (error) { console.error(error); return null; } } /**fetch POST 封装 * @param {*} route 路由 * @param {*} data POST 内容 * @returns Promise */ async function postFetch(route, body = {}) { try { const response = await fetch(prevURL + route, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ data: body }), data: body }) if (!response.ok) { throw new Error('请求失败'); } const data = await response.json(); return data; } catch (error) { console.error(error); return null; } } function postXHR(route, body) { // 创建一个新的XHR对象 var xhr = new XMLHttpRequest(); // 设置请求方法和URL xhr.open('POST', prevURL + route, true); // 设置请求头(可选) xhr.setRequestHeader('Content-Type', 'application/json'); // 设置响应类型(可选) xhr.responseType = 'json'; // 发送请求 xhr.send(JSON.stringify({ data: 'example' })); // 输出发送的数据(可选) console.log('发送的数据:', { data: 'example' }); // 处理响应事件 xhr.onload = function () { if (xhr.status === 200) { // 请求成功 console.log('请求成功'); console.log(xhr.response); } else { // 请求失败 console.log('请求失败'); } }; // 处理错误事件(可选) xhr.onerror = function () { console.log('请求发生错误'); }; } // NOTE: 1. 在 UI 界面开个 button 调出页面 const jq = jQuery; const $ = jQuery; // 添加菜单栏按钮 jq("#desktopNavbar > ul").append( "