Greasy Fork is available in English.

Diskuse » Development

请教一下,github.com转githubfast.com的match要如何整才科学。

dub
§
Posted: 26. 01. 2024

//@match *//*github.com/*
//@match *//*github*/*
//@match *//*.github.com/*
这三个还不能代表github.com的所有可能么?
关键是脚本没反应。

第一个 GitHub 国内第三方加速:这个管用,但误杀太多,连百度翻译、https://community.adobe.com/ 都会变得不正常,感觉网页表面有一个层,让原网页不能正常显示。我现在只能碰到一个用// @exclude 排除一个,这显然不科学。
这个里边用://@match *//*/*  应该是对的,不对的可能是下边的架构或正则。
这个不能识别直接输在地址栏里的网址,只用是在已有页内的网址上跳转。
https://greasyfork.org/zh-CN/scripts/480782-github-%E5%9B%BD%E5%86%85%E7%AC%AC%E4%B8%89%E6%96%B9%E5%8A%A0%E9%80%9F


第二个 GitHub.com国内加速访问
有人推荐这个,但这个没反应。直接失效
或许这个的修正@match后很管用,改成//@match *//*/* 能将址栏手输的都跳转了,改成//@match *//*github.com/*  就没反应了。
https://greasyfork.org/zh-CN/scripts/480266-github-com%E5%9B%BD%E5%86%85%E5%8A%A0%E9%80%9F%E8%AE%BF%E9%97%AE


// ==UserScript==
// @name         GitHub to GitHubFast Redirector
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Redirects GitHub links and pages to GitHubFast domain
// @author       You
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    const githubRegex = /^(https?:\/\/)?(www\.)?([a-z0-9]+\.)*github\.com(\/.*)?$/;

    function replaceGitHubLink(url) {
        return url.replace(githubRegex, function(match, protocol, www, subdomain, path) {
            subdomain = subdomain ? subdomain.replace('.', '') + '.' : '';
            return `${protocol || 'https://'}${subdomain}githubfast.com${path || ''}`;
        });
    }

    // Redirect GitHub pages immediately
    if (githubRegex.test(window.location.href)) {
        window.location.replace(replaceGitHubLink(window.location.href));
    }

    // Observer for anchor elements
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.addedNodes) {
                mutation.addedNodes.forEach(node => {
                    if (node.nodeType === 1 && node.tagName === 'A') {
                        let link = node.getAttribute('href');
                        if (link && githubRegex.test(link)) {
                            node.setAttribute('href', replaceGitHubLink(link));
                        }
                    }
                });
            }
        });
    });

    observer.observe(document, {
        childList: true,
        subtree: true
    });
})();


https://chat.openai.com/share/3c77107c-f912-4aa9-b172-e63853f8f0a6

我上不到githubfast.com, 測試不到

有其他需要的話跟上面的ChatGPT講進行調整

dub
§
Posted: 27. 01. 2024

@𝖢𝖸 𝖥𝗎𝗇𝗀
非常感谢,脚本起作用了。

但如果你直接在地址栏输入:
www.github.com之类的是没有反应的,还是会直连github.com

也就是只能从页面跳转,不能从地址栏跳转。

@𝖢𝖸 𝖥𝗎𝗇𝗀非常感谢,脚本起作用了。但如果你直接在地址栏输入:www.github.com 之类的是没有反应的,还是会直连 github.com也就是只能从页面跳转,不能从地址栏跳转。

這個UserScript沒辦法

要使用extension: https://chromewebstore.google.com/detail/url-redirector/kpdinddojclpdndplpblgckkfepjplie

@𝖢𝖸 𝖥𝗎𝗇𝗀非常感谢,脚本起作用了。但如果你直接在地址栏输入 :www.github.com 之类的是没有反应的,还是会直连 github.com也就是只能从页面跳转,不能从地址栏跳转。

這個 UserScript 沒辦法

要使用extension:
https://chromewebstore.google.com/detail/url-redirector/kpdinddojclpdndplpblgckkfepjplie

留意分別要加四個

https://github.com

https://www.github.com

http://github.com

http://www.github.com

dub
§
Posted: 28. 01. 2024

这个插件也不是很科学
设为
github.com http://githubfast.com

可以在地址栏跳转,可是又把本页跟你聊天的页面的上一级给毙了。
好像是因为上一级的链接里含有两个github.com ,直接干出了两个http://githubfast.com http://githubfast.com

说是重定向次数过多。

dub
§
Posted: 29. 01. 2024

githubfast.com已被封禁了。

Post reply

Sign in to post a reply.