// ==UserScript== // @icon https://github.githubassets.com/favicon.ico // @name FastGithub 镜像加速访问、克隆和下载 // @namespace RC1844.FastGithub // @author RC1844 // @homepageURL https://github.com/RC1844/FastGithub // @supportURL https://github.com/RC1844/FastGithub/issues // @license MIT License // @description 镜像访问GitHub,极速Clone、Release/Raw/Zip加速;十几个站点可供选择;前往项目Github仓库查看免费搭建Github镜像站点方法 // @include *://github.com/* // @include *://github* // @include *://hub.fastgit.xyz/* // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.slim.min.js // @version 1.6.6 // ==/UserScript== (function () { //=true为启用,=false为禁用 var clone = true; // var clone = false; var depth = true; // var depth = false; var Setting = ""; if (clone) { Setting += "git clone "; if (depth) { Setting += "--depth=1 "; } } var MirrorUrl = new Array();//["Url", "Name", "Tip"] MirrorUrl[0] = ["https://github.com.cnpmjs.org", "Cnpmjs", "由cnpmjs.org提供"]; MirrorUrl[1] = ["https://hub.fastgit.xyz", "FastGit", "由@KevinZonda推动的FastGit项目,请仔细甄别"]; MirrorUrl[2] = ["https://github.wuyanzheshui.workers.dev", "CF加速 1", "每日10万次调用上限,由wuyanzheshui提供"]; MirrorUrl[3] = ["https://github.bajins.com", "Bajins", "Bajins的个人站点"]; MirrorUrl[4] = ["https://download.fastgit.org", "FastGit", MirrorUrl[1][2]]; MirrorUrl[5] = ["https://github.rc1844.workers.dev", "CF加速 2", "每日10万次调用上限,由@RC1844提供"]; MirrorUrl[6] = ["https://gitclone.com/github.com", "GitClone", "GitHub缓存加速网站,1元开会员尽享极速"]; MirrorUrl[7] = ["git@git.zhlh6.cn:", "加速你的Github", "利用ucloud提供的GlobalSSH"]; MirrorUrl[8] = ["https://github-speedup.laiczhang.com", "laiczhang", "laiczhang的个人站点"]; MirrorUrl[9] = ["https://cdn.jsdelivr.net/gh", "jsDelivr", "项目当前分支总文件大小不可超过 50MB"]; MirrorUrl[10] = ["https://ghproxy.com/https://github.com", "Ioiox", "CN2 GIA 线路"]; MirrorUrl[11] = ["https://raw.fastgit.org", "FastGit", MirrorUrl[1][2]]; MirrorUrl[12] = ["https://cdn.staticaly.com/gh", "Statically", "只能浏览图片和源代码文件,文件大小限制为30MB"] MirrorUrl[13] = ["git@ssh.fastgit.org", "FastGit", "MirrorUrl[1][2]"] // MirrorUrl[14] = ["https://iapk.cc/github?url=https://github.com", "IAPK", "IAPK工具箱·Github下载器"] // MirrorUrl[15] = ["https://gh.haval.gq", "CF加速 3", "每日10万次调用上限,由@Ecalose提供"] MirrorUrl[16] = ["https://cors.zme.ink/https://github.com", "netnr", "由@netnr提供"] //添加对应索引即可使用 var CloneSet = [1, 13, 0, 6, 10]; var MirrorSet = [1, 0, 3, 2, 5, 16]; var DownloadSet = [4, 2, 5, 10]; var RawSet = [3, 2, 5]; //其他 var OtherUrl = new Array(); OtherUrl = [ ["https://github.com/RC1844/FastGithub", "脚本Github仓库地址,点个赞谢谢"], ["https://greasyfork.org/zh-CN/scripts/397419", "GreasyFork地址,希望可以给我评分收藏"], ["https://doc.fastgit.org/", "FastGit,请仔细甄别"], ["https://minhaskamal.github.io/DownGit", "DownGit"], ["https://zhoudaxiaa.gitee.io", "DownGit 周大侠啊"], ["https://gitclone.com", "GitClone,1元开会员"], ["https://d.serctl.com", "GitHub中转下载"], ["https://gitee.com/organizations/mirrors/projects", "Gitee 极速下载"], ["https://codechina.csdn.net/mirrors", "CSDN Mirrors 镜像仓库"], ["https://toolwa.com", "孟坤工具箱"], ["https://github.zhlh6.cn/", "加速你的Github"], ["http://gitd.cc", "GitHub代下服务"], ["https://gh.isteed.cc", "gh-proxy部署站点1"], ["https://github.zsxwz.workers.dev", "gh-proxy部署站点2"], ["https://gh.api.99988866.xyz", "gh-proxy部署站点3"], ["https://gh.sky-and-poem.fun", "gh-proxy部署站点4"], ["https://github.b15.me", "gh-proxy部署站点5"], ["https://github.xxyyzz.workers.dev", "gh-proxy部署站点6"], ["https://gh.argv.cc", "gh-proxy部署站点6"], ]; var CloneList = addCloneList(); var OtherList = addOtherList(); var isPC = IsPC(); function callback(_mutationList, _observer) { setTimeout(run, 1500); } const observer = new MutationObserver(callback); observer.observe(document.querySelector("head"), { attributes: true, childList: true }); var pathname; function run() { if (location.pathname != pathname) { pathname = location.pathname; $("#mirror-menu").remove(); addMenus(CloneList + addBrowseList() + OtherList); if (location.pathname.split("/")[3] == "releases") addReleasesList(); if (isPC) addDownloadZip(); addRawList(); } } run(); /** * 添加Raw列表 */ function addRawList() { $("#raw-url").each(function () { var href = $(this).attr("href"); rawHtml(11, MirrorUrl[11][0] + href.replace("/raw", "")); RawSet.forEach((element) => { rawHtml(element, MirrorUrl[element][0] + href); }); rawHtml(9, MirrorUrl[9][0] + href.replace("/raw/", "@")); rawHtml(12, MirrorUrl[12][0] + href.replace("/raw", "")); function rawHtml(element, Url) { var span = $("#raw-url").clone().removeAttr("id"); span.attr({ href: Url, title: MirrorUrl[element][2], target: "_blank", }); span.text(MirrorUrl[element][1]); $("#raw-url").before(span); } }); } /** * Fast Download ZIP */ function addDownloadZip() { $("a[data-open-app='link']").each(function () { var span = $(`
  • `); var href = $(this).attr("href"); var clone = $(this) .clone() .removeAttr("data-hydro-click data-hydro-click-hmac data-ga-click"); clone.addClass("Box-row Box-row--hover-gray"); DownloadSet.forEach((element) => { var span1 = clone.clone(); span1.attr({ href: MirrorUrl[element][0] + href, title: MirrorUrl[element][2], }); span1.html( span1.html().replace("Download ZIP", `Download ZIP(${MirrorUrl[element][1]})`) ); span.append(span1); }); $(this).parent().after(span); }); } /** * 添加Releases列表 */ function addReleasesList() { $(".Box--condensed").find("[href]").each(function () { var href = $(this).attr("href"); $(this).parent().after(`
    ` + downloadHref(href) + `
    `); $(this).parent().removeClass("Box-body"); function downloadHref(href) { var span = ""; DownloadSet.forEach((element) => { span += `${MirrorUrl[element][1]}`; }); return span; } }); } /** * 检测是否为PC端 */ function IsPC() { var userAgentInfo = navigator.userAgent; var Agents = [ "Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod", ]; var flag = true; const len = Agents.length; for (var v = 0; v < len; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } return flag; } /** * 添加菜单列表 */ function addMenus(info) { if (isPC) $("#repository-details-container > ul.pagehead-actions").prepend(`
  • ${info}
  • `); else $("span.Label.Label--secondary.v-align-middle.mr-1").after(`${info}`); } /** * 添加克隆列表 */ function addCloneList() { var href = window.location.href.split("/"); var git = href[3] + "/" + href[4] + ".git"; var info = `
    克隆与镜像
    镜像站点与快速克隆
    `; //克隆列表 CloneSet.forEach((element) => { info += cloneHtml(Setting + MirrorUrl[element][0] + "/" + git, MirrorUrl[element][1]); }); info += cloneHtml(Setting + MirrorUrl[7][0] + git, MirrorUrl[7][1]); info += cloneHtml("git remote set-url origin https://github.com/" + git, "还原GitHub仓库地址"); function cloneHtml(Url, Tip) { return `
    `; } return info; } /** * 添加镜像浏览列表 */ function addBrowseList() { var info = ``; var href = window.location.href.split("/"); var path = window.location.pathname; MirrorSet.forEach((element) => { info += listHtml(MirrorUrl[element][0] + path, `镜像浏览(${MirrorUrl[element][1]})`, MirrorUrl[element][2]); }); if ( href.length == 5 || path.includes("/tree/") || path.includes("/blob/") ) { var Html = MirrorUrl[9][0] + path.replace("/tree/", "@").replace("/blob/", "@"); if (!path.includes("/blob/")) { Html += "/"; } info += listHtml(Html, `镜像浏览(${MirrorUrl[9][1]})`, MirrorUrl[9][2]); } if (location.hostname != "github.com") { info += listHtml(`https://github.com${path}`, "返回GitHub"); } return info; } /** * 添加其他列表 */ function addOtherList() { var info = `
    `; return info; } function listHtml(Url, Name, Tip = "") { return ` ${Name} `; } })();