MirrorsProxy.Download

指南/油猴脚本:浏览 GitHub 时一键加速

油猴脚本:浏览 GitHub 时一键加速

用 Tampermonkey 油猴脚本把 GitHub 页面上的 Release / Raw / 压缩包链接自动替换为镜像加速地址,浏览时点下载即走镜像。

适合「经常在网页上点下载」的人:装一个油猴脚本,GitHub 页面上的下载链接自动变成镜像直链,无需每次复制粘贴到工具站。

安装

  1. 浏览器装 Tampermonkey(Chrome / Edge / Firefox / Safari 均有)。
  2. 新建脚本,粘贴下面代码,保存。
  3. 打开任意 GitHub 仓库 / Release 页,下载链接即已替换为镜像地址(鼠标悬停可见)。

脚本

// ==UserScript==
// @name         GitHub 镜像加速下载
// @namespace    mirrordl
// @version      1.0
// @description  把 GitHub 的 Release/Raw/压缩包链接替换为镜像加速地址
// @match        https://github.com/*
// @grant        none
// ==/UserScript==
(function () {
  const MIRROR = 'https://gh-proxy.com/'; // 可换 ghproxy.net / ghproxy.vip 等
  const RE = /^https:\/\/(github\.com\/[^/]+\/[^/]+\/(releases\/download|archive)\/|raw\.githubusercontent\.com\/)/;
  function rewrite() {
    document.querySelectorAll('a[href]').forEach((a) => {
      const href = a.href;
      if (RE.test(href) && !href.startsWith(MIRROR)) {
        a.href = MIRROR + href;
        a.title = '镜像加速: ' + href;
      }
    });
  }
  rewrite();
  // GitHub 是 SPA / 动态加载,监听 DOM 变化
  new MutationObserver(rewrite).observe(document.body, { childList: true, subtree: true });
})();

说明与注意

  • 只改写 releases/download/、archive/、raw.githubusercontent.com 三类文件直链,不影响页面导航 / clone 按钮。
  • 镜像节点失效时改 MIRROR 常量即可;多节点回退需自行扩展。
  • 脚本只改链接指向,不校验内容;敏感文件仍请核对哈希。
  • 不想装脚本?直接用首页工具粘贴链接,或整站换源。

← 返回转换工具