// ==UserScript== // @name 下载路由 | Download Router // @namespace https://github.com/mks155 // @homepageURL https://github.com/mks155/DownloadRouter // @icon https://raw.githubusercontent.com/mks155/DownloadRouter/refs/heads/main/docs/icon.svg // @version 1.0.5 // @description 接管浏览器任意下载链接,快速调起分发给迅雷 / 比特彗星等客户端。识别漏网就按住 Alt+右键。 | Take over any download link in the browser, quickly launch and distribute it to clients such as Thunderbolt / BitComet. To identify any missed links, hold down Alt and right-click. // @author mks155 // @license Apache-2.0 // @match *://*/* // @run-at document-idle // @sandbox raw // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant GM_getValue // @grant GM_setValue // @noframes // ==/UserScript== (() => { 'use strict'; const LS_KEY = 'download_router_config'; // 顶层只取引用不解析;解析推迟到打开设置面板时 const SELF_SRC = (document.currentScript && document.currentScript.textContent) || ''; const META = (typeof GM_info !== 'undefined' && GM_info.script) || {}; /** 元数据块是版本号与图标的唯一来源。TM 免申请即给 GM_info,其余引擎走自身源码 */ function meta(key) { if (key in META) return META[key] || ''; const m = SELF_SRC && new RegExp('^[ \\t]*//[ \\t]*@' + key + '[ \\t]+(.+?)[ \\t]*$', 'm').exec(SELF_SRC); return m ? m[1] : ''; } const DEFAULT_CONFIG = { launchMethod: 'href', // href | anchor forceOnAlt: true, theme: 'auto', // auto | light | dark }; const LAUNCH_METHODS = { href: '地址栏', anchor: '链接触发' }; const THEMES = { auto: { name: '跟随系统', desc: '按浏览器的深浅色设置自动切换' }, light: { name: '浅色', desc: '始终用浅色菜单' }, dark: { name: '深色', desc: '始终用深色菜单' }, }; const CONFIG = { ...DEFAULT_CONFIG, ...loadConfig() }; if (!LAUNCH_METHODS[CONFIG.launchMethod]) CONFIG.launchMethod = 'href'; if (!THEMES[CONFIG.theme]) CONFIG.theme = 'auto'; function loadConfig() { try { return GM_getValue(LS_KEY, {}) || {}; } catch { return {}; } } function saveConfig() { try { GM_setValue(LS_KEY, CONFIG); return true; } catch { return false; } } /** 内联