FastGit

GitHub Clone or download、Releases 下载加速

  1. // ==UserScript==
  2. // @name FastGit
  3. // @version 0.8
  4. // @description GitHub Clone or download、Releases 下载加速
  5. // @author Vhxubo
  6. // @license MIT
  7. // @icon https://github.githubassets.com/favicon.ico
  8. // @homepage https://gist.github.com/vhxubo/d67fbd5bb3b7308b2e3690ca58e12c12
  9. // @namespace https://gist.github.com/vhxubo/d67fbd5bb3b7308b2e3690ca58e12c12
  10. // @match https://github.com/*/*
  11. // @match https://hub.fastgit.org/*/*
  12. // @grant none
  13. // @note 2020.07.02_V0.8 适配新版 UI(Code);修改 Releases 下载方式(更直观);支持 hub.fastgit.org
  14. // @note 2020.06.30_V0.7 修改 Releases 下载接口
  15. // @note 2020.06.29_V0.6 Releases 界面点击文件体积下载,不支持 Source code 下载
  16. // @note 2020.06.27_V0.5 适配新版 UI
  17. // @note 2020.05.06_V0.4 新增: zipProxy - zip 下载链接
  18. // ==/UserScript==
  19.  
  20. (function () {
  21. 'use strict';
  22. var gitProxy = 'https://hub.fastgit.org';
  23. var sshProxy = 'git@fastgit.org';
  24. var releaseProxy = 'https://download.fastgit.org';
  25.  
  26. if (window.location.href.indexOf('releases') === -1) {
  27. var regex = /"((\/.*)+\.zip)"/;
  28. var domDownload = document.querySelector('span.d-flex')||document.querySelector('get-repo-controller')||document.querySelector('get-repo');
  29. if (domDownload !== null) {
  30. var oldHtml = domDownload.outerHTML;
  31. var zipLink = gitProxy + regex.exec(oldHtml)[1];
  32. var outHtml = oldHtml
  33. .replace('Clone or download', 'FastGit')
  34. .replace('Clone', 'FastGit')
  35. .replace('Code', 'FastGit')
  36. .replace(/https:\/\/github.com/g, gitProxy)
  37. .replace(regex, zipLink)
  38. .replace(/git@github.com/g, sshProxy)
  39. .replace('https%3A%2F%2Fgithub.com', 'https%3A%2F%2Fhub.fastgit.org');
  40.  
  41. domDownload.insertAdjacentHTML('afterend', outHtml);
  42. }
  43. } else {
  44. var resDownload = document.querySelectorAll('.Box--condensed small');
  45. if (resDownload !== null) {
  46. var i;
  47. for (i = 0; i < resDownload.length; i++) {
  48. var resHref = resDownload[i].previousElementSibling.getAttribute('href');
  49. resDownload[i].insertAdjacentHTML(
  50. 'beforeend',
  51. `<a title="FastGit 加速" class="pl-2 text-bold" href="${
  52. releaseProxy + resHref
  53. }">Download</a>`
  54. );
  55. }
  56. }
  57. }
  58. })();