// ==UserScript== // @icon https://github.githubassets.com/favicon.ico // @name GitHub镜像加速访问、克隆和下载 // @namespace RC1844.FastGithub // @author RC1844 // @homepageURL https://github.com/RC1844/FastGithub // @supportURL https://github.com/RC1844/FastGithub/issues // @license MIT License // @description 镜像访问GitHub、加速克隆和下载;适配Github新UI;增加新克隆站点;前往项目Github仓库查看免费搭建Github镜像站点方法 // @include *://github.com/* // @include *://github* // @include *://hub.fastgit.org/* // @require http://cdn.bootcss.com/jquery/1.8.3/jquery.min.js // @version 1.5.1 // @grant GM_addStyle // @downloadURL none // ==/UserScript== (function () { "use strict"; //=true为启用,=false为禁用 var clone = true; // var clone = false; var depth = true; // var depth = false; var str1 = ""; if (clone) { str1 += "git clone "; if (depth) { str1 += "--depth=1 "; } } var MirrorUrl = new Array(); MirrorUrl[0] = "https://github.com.cnpmjs.org"; MirrorUrl[1] = "https://hub.fastgit.org"; MirrorUrl[2] = "https://github.wuyanzheshui.workers.dev"; MirrorUrl[3] = "https://github.bajins.com"; MirrorUrl[4] = "https://download.fastgit.org"; MirrorUrl[5] = "https://github.rc1844.ml"; MirrorUrl[6] = "https://gitclone.com/github.com"; MirrorUrl[7] = "git@git.zhlh6.cn:"; MirrorUrl[8] = "https://github-speedup.laiczhang.com"; MirrorUrl[9] = "https://cdn.jsdelivr.net/gh"; //添加对应索引即可使用 var CloneSet = [1, 8, 0, 6]; var MirrorSet = [1, 8, 0, 3, 2, 5]; var DownloadSet = [4, 8, 2, 5]; var RawSet = [1, 3, 2, 5]; //其他 var OtherUrl = new Array(); OtherUrl = [ { url: "https://github.com/RC1844/FastGithub", name: "脚本Github仓库地址,点个赞谢谢", }, { url: "https://greasyfork.org/zh-CN/scripts/397419", name: "GreasyFork地址,希望可以给我评分收藏", }, { url: "https://minhaskamal.github.io/DownGit", name: "DownGit", }, { url: "https://d.serctl.com/", name: "GitHub中转下载", }, { url: "https://github.zhlh6.cn/", name: "加速你的Github", }, { url: "http://gitd.cc/", name: "GitHub代下载", }, { url: "https://gh.isteed.cc/", name: "gh-proxy部署站点", }, { url: "https://github.zsxwz.workers.dev/", name: "gh-proxy部署站点", }, { url: "https://gh.api.99988866.xyz/", name: "gh-proxy部署站点", }, { url: "https://g.ioiox.com/", name: "gh-proxy部署站点", }, { url: "https://gh.sky-and-poem.fun/", name: "gh-proxy部署站点", }, // { // url: "", // name: "", // }, ]; var a = window.location.href.split("/"); var str2 = a[3] + "/" + a[4] + ".git"; var str3 = window.location.pathname; //镜像列表 // $("div.flex-auto.min-width-0.width-fit.mr-3") $("h1.flex-wrap.break-word.text-normal").each(function () { var info = `
镜像网站
镜像站点与快速克隆
`; //克隆列表 for (let i in CloneSet) { info += cloneHtml(str1 + MirrorUrl[CloneSet[i]] + "/" + str2); } info += cloneHtml(str1 + MirrorUrl[7] + str2); //浏览列表 for (let i in CloneSet) { info += listHtml(MirrorUrl[MirrorSet[i]] + str3, `镜像浏览${i}`); } if (a.length == 5 || str3.includes("/tree/") || str3.includes("/blob/")) { var Html = MirrorUrl[9] + str3.replace("/tree/", "@").replace("/blob/", "@"); if (!str3.includes("/blob/")) { Html += "/"; } info += listHtml(Html, "jsDelivr"); } if (location.hostname != "github.com") { info += listHtml(`https://github.com${str3}`, "返回GitHub"); } info += `
`; function cloneHtml(Url) { return `
`; } function listHtml(Url, Name) { return ` ${Name} `; } $(this).append(info); }); //Fast Download ZIP $("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"); for (const i in DownloadSet) { if (DownloadSet.hasOwnProperty(i)) { const element = DownloadSet[i]; var span1 = clone.clone(); span1.attr({ href: MirrorUrl[element] + href, title: MirrorUrl[element], }); span1.html(span1.html().replace("Download ZIP", `Fast Download ZIP${i}`)); span = span.clone().append(span1); } } $(this).parent().after(span); }); //Download Releases $(".Box--condensed").each(function () { $(this).find(".flex-items-center>a").each(function () { var href = $(this).attr("href"); var span = ""; if (isMobile()) { span = `
    ` + downloadHref(href) + `
    `; } else { span = `` + downloadHref(href) + ``; } $(this).next().append(span); }); if (isMobile()) { $(this).find(".d-flex").removeClass("d-flex"); } $(this).find(".d-block.Box-body>a").each(function () { var href = $(this).attr("href"); $(this).after(`` + downloadHref(href) + ``); $(this).parent().addClass("d-flex flex-justify-between"); }); }); // Raw $("#raw-url").each(function () { var href = $(this).attr("href"); var text = $(this).text(); for (const i in RawSet) { if (RawSet.hasOwnProperty(i)) { const element = RawSet[i]; var span = $(this).clone().removeAttr("id"); span.attr({ href: MirrorUrl[element] + href, title: MirrorUrl[element], target: "_blank", }); span.text(text + i); $(this).before(span); } } var span = $(this).clone().removeAttr("id"); span.attr({ href: MirrorUrl[9] + href.replace("/raw/", "@"), title: MirrorUrl[9], target: "_blank", }); span.text("jsDelivr"); $(this).before(span); }); function downloadHref(href) { var span = ""; for (let i in DownloadSet) { span += `快速下载${i}`; } return span; } async function isMobile() { var userAgent = navigator.userAgent; console.log(userAgent); let agents = [ "Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod", ]; for (let agent of agents) { if (userAgent.indexOf(agent) > 0) { console.log(agent); return true; } } return false; } })();