// ==UserScript== // @name RPC切换 // @namespace http://tampermonkey.net/ // @version 0.4 // @description 方便地切换RPC主机地址及其他设置 // @author jiemo // @match *://pan.quark.cn/* // @grant unsafeWindow // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 定义多个RPC配置 const rpcConfigs = [ { address: 'https://1.de', downloadPath: '/downloads', port: 443 }, { address: 'https://2.de', downloadPath: '/root/downloads', port: 443 }, { address: 'https://3.de', downloadPath: '/downloads', port: 443 } ]; // 切换RPC配置的函数 const rpcSwitcher = function(config) { unsafeWindow.base.setValue('setting_rpc_domain', config.address); unsafeWindow.base.setValue('setting_rpc_dir', config.downloadPath); unsafeWindow.base.setValue('setting_rpc_port', config.port); }; // 创建一个下拉选择框来切换RPC配置 const select = document.createElement('select'); select.className = 'ant-select-selection ant-select-selection--single'; select.style.width = '250px'; select.style.fontSize = '15px'; rpcConfigs.forEach((config) => { const option = document.createElement('option'); option.value = JSON.stringify(config); option.text = config.address; select.appendChild(option); }); select.onchange = function() { const selectedConfig = JSON.parse(this.value); rpcSwitcher(selectedConfig); }; // 将下拉选择框放置在指定的按钮右侧 function init() { const targetButton = document.querySelector('.ant-btn.btn-file.btn-create-folder'); if (targetButton) { if (select.parentNode) { select.parentNode.removeChild(select); } targetButton.parentNode.insertBefore(select, targetButton.nextSibling); // 获取当前配置并设置下拉框的值 const currentRpcAddress = unsafeWindow.base.getValue('setting_rpc_domain'); const currentDownloadPath = unsafeWindow.base.getValue('setting_download_path'); const currentRpcPort = unsafeWindow.base.getValue('setting_rpc_port'); const currentConfig = rpcConfigs.find(config => config.address === currentRpcAddress && config.downloadPath === currentDownloadPath && config.port === currentRpcPort ); if (currentConfig) { select.value = JSON.stringify(currentConfig); } } } init(); // 监听网址变化 window.addEventListener('hashchange', init); window.addEventListener('popstate', init); })();