Greasy Fork

Greasy Fork is available in English.

RPC切换

方便地切换RPC主机地址

目前为 2025-04-28 提交的版本。查看 最新版本

// ==UserScript==
// @name         RPC切换
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  方便地切换RPC主机地址
// @author       jiemo
// @match        *://pan.quark.cn/*
// @grant        unsafeWindow
// @license MIT
// ==/UserScript==

(function() {
  'use strict';
  const rpcAddresses = [
    'https://1.de',
    'https://2.de',
    'https://3.de'
  ];

  const rpcSwitcher = function(value) {
    unsafeWindow.base.setValue('setting_rpc_domain', value);
  };

  // 创建一个下拉选择框来切换RPC主机地址
  const select = document.createElement('select');
  select.className = 'ant-select-selection ant-select-selection--single';
  select.style.width = '250px';
  select.style.fontSize = '15px';

  rpcAddresses.forEach((address) => {
    const option = document.createElement('option');
    option.value = address;
    option.text = address;
    select.appendChild(option);
  });

  select.onchange = function() {
    rpcSwitcher(this.value);
  };

  // 将下拉选择框放置在指定的按钮右侧
  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');
      select.value = currentRpcAddress;
    }
  }

  init();

  // 监听网址变化
  window.addEventListener('hashchange', init);
  window.addEventListener('popstate', init);
})();