FastGit

GitHub Clone or download、releases 下载加速

当前为 2020-04-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name FastGit
  3. // @version 0.3
  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. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16. var gitProxy = 'https://hub.fastgit.org';
  17. var sshProxy = 'git@fastgit.org';
  18. var releaseProxy = 'https://release.fastgit.org';
  19.  
  20. if (window.location.href.indexOf('releases') === -1) {
  21. var regex = /"((\/.*)+\.zip)"/;
  22. var domDownload = document.querySelector('span.d-flex');
  23. if (domDownload !== null) {
  24. var oldHtml = domDownload.outerHTML;
  25. var zipLink = gitProxy + regex.exec(oldHtml)[1];
  26. var outHtml = oldHtml
  27. .replace('Clone or download', 'FastGit')
  28. .replace(/https:\/\/github.com/g, gitProxy)
  29. .replace(regex, zipLink)
  30. .replace(/git@github.com/g, sshProxy)
  31. .replace('https%3A%2F%2Fgithub.com', 'https%3A%2F%2Fhub.fastgit.org');
  32.  
  33. domDownload.insertAdjacentHTML('afterend', outHtml);
  34. }
  35. } else {
  36. var resDownload = document.querySelectorAll('.Box--condensed a');
  37. if (resDownload !== null) {
  38. var i;
  39. for (i = 0; i < resDownload.length; i++) {
  40. var resHref = resDownload[i].getAttribute('href');
  41. resDownload[i].insertAdjacentHTML(
  42. 'afterend',
  43. `<a style="cursor: pointer;" href="${
  44. releaseProxy + resHref
  45. }">FastGit Download</a>`
  46. );
  47. }
  48. }
  49. }
  50. })();