0x00 前言

最近 Github 不仅访问慢, 下载的速度更是让人头皮发麻!

于是我就在思考怎么解决这个问题, 碰巧让我发现了, 码云可以直接导入 Github 仓库, 然后在码云那里下载, 速度飞快!

本来还想水一篇文章, 但是懒癌发作, 拖到现在, 结果发现已经有大佬发出来了... 链接如下:

教你一招搞定 GitHub 下载加速!

咦, 竟然有教程了, 那我还写这篇文章干啥?

当然是因为, 码云虽然可以同步 github 仓库下载源代码, 但是 release 没办法同步过去, 所以下载不了 release. 因此, 就有了本文章.

0x01github 镜像站

找了好久, 终于找到了一个大佬搭建的 github 镜像站: https://github.strcpy.cn

那这玩意咋用啊? 举个栗子!

当我们要下载 vnote 源码时, 可以看到下载链接是https://github.com/tamlok/vnote/archive/master.zip

然后我们直接将https://github.com 替换成 https://github.strcpy.cn, 所以现在链接变成了https://github.strcpy.cn/tamlok/vnote/archive/master.zip, 直接将该链接粘贴到浏览器上, 你就可以体验飞一样的速度了.

同理, 如果要下载 release, 也是同样的替换链接!

比如:   https://github.com/tamlok/vnote/releases/download/v2.9/VNote-2.9-x64.dmg
替换后:  https://github.strcpy.cn/tamlok/vnote/releases/download/v2.9/VNote-2.9-x64.dmg

0x02 脚本

马克思说了, 能拖则拖~~ 额, 是能用脚本就用脚本!

谷歌浏览器装 Tampermonkey 插件 -> 添加新脚本, 将下面的代码粘贴上去

// ==UserScript==
// @name         自动替换 github 下载地址
// @namespace    undefined
// @version      0.1
// @description  将 github.com 替换成 github.strcpy.cn, 这样子下载就可以加速了
// @author       江南小虫虫
// @match        *://github.com/*
// @require      https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    if(window.location.href.search("releases") != -1){
        // release 页面
        var links = $(".Box.Box--condensed.mt-3").find('a');
        links.each(function(index,value){
            var new_link = "https://github.strcpy.cn" + $(this).attr("href");
            $(this).attr("href", new_link);
            console.log("新链接: " + $(this).attr("href"));
        });
    }else{
        //flex-1 btn btn-outline get-repo-btn
        // 先找 github 页面的压缩包
        var github_link = $(".flex-1.btn.btn-outline.get-repo-btn");
        var t = github_link.attr("href");
        if(typeof(t) != "undefined"){
            var new_link = "https://github.strcpy.cn" + t;
            console.log("测试: "+ github_link.attr("href"));
            console.log("新链接: " + new_link);
            github_link.attr("href", new_link);
        }else{
            console.log("不是需要下载的两个页面之一");
        }
    }
})();

然后Ctrl+S保存, 该脚本就会自动生效了.

我们可以看一下效果

发现链接已经自动替换好了, 所以我们直接点击下载即可.

0x03 后记

以下是注意事项:

1. 本代理不支持,git clone
2. 缓存原因,第一次下载可能会比较慢。待完全拉取完缓存后,速度会非常快。
3. github下载mirror站,目前限制速度是10M/s,仅限国内使用,如果使用了代理,请注意关闭。
4. 会根据upyun后台日志,分析恶意流量,对url进行封禁。请勿恶意使用。

如果未来某一天, 这个 github 镜像站挂了, 那 github 就下载不了东西了, 所以需要将我们刚刚添加的脚本删了就行.

最后附上这位无私奉献的大佬的博客:

https://jinfeijie.cn/post-805.html?unapproved=305&moderation-hash=c980242548e1e50ce7ec596446c73248#comment-305

最后修改:2020 年 05 月 18 日 10 : 46 PM
如果觉得我的文章对你有用,请随意赞赏