您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Intercept magnet links and open qBittorrent download dialog in a popup.
当前为
// ==UserScript== // @name Magnet Link Handler for qBittorrent WebUI // @namespace http://tampermonkey.net/ // @version 1.0 // @description Intercept magnet links and open qBittorrent download dialog in a popup. // @match *://*/* // @grant GM_getValue // @grant GM_setValue // @grant GM_registerMenuCommand // @license MIT // ==/UserScript== (function() { 'use strict'; // Define the default qBittorrent WebUI URL const defaultQbWebUIHost = 'http://localhost:8080'; // Retrieve the saved qBittorrent WebUI URL or use the default let qbWebUIHost = GM_getValue('qbWebUIHost', defaultQbWebUIHost); // Add a menu command to set the qBittorrent WebUI URL GM_registerMenuCommand('Set qBittorrent WebUI URL', () => { const newUrl = prompt('Enter the qBittorrent WebUI URL:', qbWebUIHost); if (newUrl) { GM_setValue('qbWebUIHost', newUrl); // Save the new URL qbWebUIHost = newUrl; // Update the script's URL alert(`qBittorrent WebUI URL set to: ${newUrl}`); } }); // Check if the current page is the qBittorrent WebUI's download.html const isDownloadPage = window.location.href.startsWith(qbWebUIHost) && window.location.pathname === '/download.html'; if (isDownloadPage) { // Check if the URL contains the `?link=` parameter const urlParams = new URLSearchParams(window.location.search); const encodedMagnetLink = urlParams.get('url'); if (!encodedMagnetLink) { return; // Exit if no `?url=` parameter is found } // Decode the magnet link const magnetLink = decodeURIComponent(encodedMagnetLink); // Function to fill the textarea with the magnet link const magnetTextarea = document.querySelector('#urls'); if (magnetTextarea) { magnetTextarea.value = magnetLink; // Fill the textarea } // Register close handler. document.querySelector('#download_frame').addEventListener("load", function() { window.close(); }); } else { // Function to handle magnet link clicks function handleMagnetLinkClick(event) { let target = event.target; while (target && target.tagName !== 'A') { target = target.parentElement; } // Check if the clicked element is a magnet link if (target?.href.startsWith('magnet:')) { event.preventDefault(); // Prevent the default behavior // Encode the magnet link for use in a URL const encodedMagnetLink = encodeURIComponent(target.href); // Open the qBittorrent WebUI's download.html in a popup const popupUrl = `${qbWebUIHost}/download.html?url=${encodedMagnetLink}`; // Define the popup dimensions const popupWidth = 500; const popupHeight = 600; // Calculate the position to center the popup const left = (window.screen.width - popupWidth) / 2; const top = (window.screen.height - popupHeight) / 2; // Open the popup with centered position window.open( popupUrl, 'qBittorrentAddMagnet', `width=${popupWidth},height=${popupHeight},left=${left},top=${top}` ); } } // Attach the event listener to the document document.addEventListener('click', handleMagnetLinkClick, true); } })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址