Skip to content

Instantly share code, notes, and snippets.

@vhxubo
Last active February 2, 2024 16:09
Show Gist options
  • Save vhxubo/d67fbd5bb3b7308b2e3690ca58e12c12 to your computer and use it in GitHub Desktop.
Save vhxubo/d67fbd5bb3b7308b2e3690ca58e12c12 to your computer and use it in GitHub Desktop.
GitHub Clone or download、releases 下载加速
// ==UserScript==
// @name FastGit
// @version 0.8
// @description GitHub Clone or download、Releases 下载加速
// @author Vhxubo
// @license MIT
// @icon https://github.githubassets.com/favicon.ico
// @homepage https://gist.github.com/vhxubo/d67fbd5bb3b7308b2e3690ca58e12c12
// @namespace https://gist.github.com/vhxubo/d67fbd5bb3b7308b2e3690ca58e12c12
// @match https://github.com/*/*
// @match https://hub.fastgit.org/*/*
// @grant none
// @note 2020.07.02_V0.8 适配新版 UI(Code);修改 Releases 下载方式(更直观);支持 hub.fastgit.org
// @note 2020.06.30_V0.7 修改 Releases 下载接口
// @note 2020.06.29_V0.6 Releases 界面点击文件体积下载,不支持 Source code 下载
// @note 2020.06.27_V0.5 适配新版 UI
// @note 2020.05.06_V0.4 新增: zipProxy - zip 下载链接
// ==/UserScript==
(function () {
'use strict';
var gitProxy = 'https://hub.fastgit.org';
var sshProxy = '[email protected]';
var releaseProxy = 'https://download.fastgit.org';
if (window.location.href.indexOf('releases') === -1) {
var regex = /"((\/.*)+\.zip)"/;
var domDownload = document.querySelector('span.d-flex')||document.querySelector('get-repo-controller')||document.querySelector('get-repo');
if (domDownload !== null) {
var oldHtml = domDownload.outerHTML;
var zipLink = gitProxy + regex.exec(oldHtml)[1];
var outHtml = oldHtml
.replace('Clone or download', 'FastGit')
.replace('Clone', 'FastGit')
.replace('Code', 'FastGit')
.replace(/https:\/\/github.com/g, gitProxy)
.replace(regex, zipLink)
.replace(/[email protected]/g, sshProxy)
.replace('https%3A%2F%2Fgithub.com', 'https%3A%2F%2Fhub.fastgit.org');
domDownload.insertAdjacentHTML('afterend', outHtml);
}
} else {
var resDownload = document.querySelectorAll('.Box--condensed small');
if (resDownload !== null) {
var i;
for (i = 0; i < resDownload.length; i++) {
var resHref = resDownload[i].previousElementSibling.getAttribute('href');
resDownload[i].insertAdjacentHTML(
'beforeend',
`<a title="FastGit 加速" class="pl-2 text-bold" href="${
releaseProxy + resHref
}">Download</a>`
);
}
}
}
})();
@vhxubo
Copy link
Author

vhxubo commented Apr 30, 2020

Hey, are you planning that publish this script to greasyfork?

It's here,please. FastGit

@KevinZonda
Copy link

KevinZonda commented Apr 30, 2020

How about add an icon to the script?

// @icon         https://github.githubassets.com/favicon.ico

image

Or

// @icon         https://avatars2.githubusercontent.com/u/62810231?s=200&v=4

image

@KevinZonda
Copy link

Btw, plz add the new replace rule which can support Open in Visual Studio.

The example code is following

.replace('https%3A%2F%2Fgithub.com', 'https%3A%2F%2Fhub.fastgit.org');

image

@KevinZonda
Copy link

@vhxubo
Copy link
Author

vhxubo commented Apr 30, 2020

You can refer to my fork

https://gist.github.com/KevinZonda/53eccb2f76a1c7f5acac45f59d455225

Thanks. Please update to v0.3.

@KevinZonda
Copy link

I have another issue. That fastgit.org provides zip booster using domain release.fastgit.org, but not give redirect signal by nginx. So you should also give a replacer to replace the Download ZIP button.

Sample:
https://release.fastgit.org/fastgitorg/PSFastGet/archive/master.zip

And we are considering that replace release.fastgit.org to download.fastgit.org.

@KevinZonda
Copy link

KevinZonda commented May 1, 2020

I have another issue. That fastgit.org provides zip booster using domain release.fastgit.org, but not give redirect signal by nginx. So you should also give a replacer to replace the Download ZIP button.

Sample:
https://release.fastgit.org/fastgitorg/PSFastGet/archive/master.zip

And we are considering that replace release.fastgit.org to download.fastgit.org.

We finished the changes. See more -> https://doc.fastgit.org/en-us/guide.html

@vhxubo
Copy link
Author

vhxubo commented May 6, 2020

I have another issue. That fastgit.org provides zip booster using domain release.fastgit.org, but not give redirect signal by nginx. So you should also give a replacer to replace the Download ZIP button.
Sample:
https://release.fastgit.org/fastgitorg/PSFastGet/archive/master.zip
And we are considering that replace release.fastgit.org to download.fastgit.org.

We finished the changes. See more -> https://doc.fastgit.org/en-us/guide.html

Get it! Please update to V0.4,and just try it.

@KevinZonda
Copy link

Hi there, can FastGit download be aligned? It's so weird now, QwQ

image

@vhxubo
Copy link
Author

vhxubo commented Jun 28, 2020

image
Update, pls.

@KevinZonda
Copy link

image
Update, pls.

LGTM, but releaseProxy is now the same with zipProxy. (release. will give a 301 redirect to download, and the api is not stable), so I think combine it into one is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment