Greasy Fork

Greasy Fork is available in English.

GitHub镜像加速

将页面中显示的和链接中的github.con替换为你的镜像github域名

当前为 2025-03-01 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         GitHub镜像加速
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  将页面中显示的和链接中的github.con替换为你的镜像github域名
// @author       鲨光狗罕见
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 定义要替换的旧域名和新域名
    const oldDomain = 'github.com';
    const newDomain = 'bgithub.xyz';

    // 替换文本中的域名
    function replaceTextNodes(node) {
        if (node.nodeType === Node.TEXT_NODE) {
            if (node.nodeValue.includes(oldDomain)) {
                node.nodeValue = node.nodeValue.replace(new RegExp(oldDomain, 'g'), newDomain);
            }
        } else {
            for (const childNode of node.childNodes) {
                replaceTextNodes(childNode);
            }
        }
    }

    // 替换链接的href属性
    function replaceHrefAttributes(link) {
        if (link.href && link.href.includes(oldDomain)) {
            link.href = link.href.replace(oldDomain, newDomain);
        }
    }

    // 初始化替换
    function initReplace() {
        // 替换所有文本节点
        replaceTextNodes(document.body);

        // 替换所有链接的href属性
        const links = document.getElementsByTagName('a');
        for (const link of links) {
            replaceHrefAttributes(link);
        }
    }

    // 页面加载完成后初始化替换
    initReplace();

    // 监控页面动态变化
    const observer = new MutationObserver(function(mutations) {
        for (const mutation of mutations) {
            if (mutation.type === 'childList') {
                for (const node of mutation.addedNodes) {
                    if (node.nodeType === Node.ELEMENT_NODE) {
                        // 替换新添加的文本节点
                        replaceTextNodes(node);

                        // 替换新添加的链接
                        if (node.tagName === 'A') {
                            replaceHrefAttributes(node);
                        } else if (node.getElementsByTagName) {
                            const links = node.getElementsByTagName('a');
                            for (const link of links) {
                                replaceHrefAttributes(link);
                            }
                        }
                    }
                }
            }
        }
    });

    // 监控document.body及其子节点的变化
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();