FastGit

GitHub Clone or download、releases 下载加速

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

  1. // ==UserScript==
  2. // @name FastGit
  3. // @version 0.2
  4. // @description GitHub Clone or download、releases 下载加速
  5. // @author Vhxubo
  6. // @license MIT
  7. // @homepage https://gist.github.com/vhxubo/d67fbd5bb3b7308b2e3690ca58e12c12
  8. // @match https://github.com/*/*
  9. // @grant none
  10. // @namespace https://gist.github.com/vhxubo/d67fbd5bb3b7308b2e3690ca58e12c12
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. var gitProxy = 'https://hub.fastgit.org';
  16. var sshProxy = 'git@fastgit.org';
  17. var releaseProxy = 'https://release.fastgit.org';
  18.  
  19. if (window.location.href.indexOf('releases') === -1) {
  20. var regex = /"((\/.*)+\.zip)"/;
  21. var domDownload = document.querySelector('span.d-flex');
  22. if (domDownload !== null) {
  23. var oldHtml = domDownload.outerHTML;
  24. var zipLink = gitProxy + regex.exec(oldHtml)[1];
  25. var outHtml = oldHtml
  26. .replace('Clone or download', 'FastGit')
  27. .replace(/https:\/\/github.com/g, gitProxy)
  28. .replace(regex, zipLink)
  29. .replace(/git@github.com/g, sshProxy);
  30.  
  31. domDownload.insertAdjacentHTML('afterend', outHtml);
  32. }
  33. } else {
  34. var resDownload = document.querySelectorAll('.Box--condensed a');
  35. if (resDownload !== null) {
  36. var i;
  37. for (i = 0; i < resDownload.length; i++) {
  38. var resHref = resDownload[i].getAttribute('href');
  39. resDownload[i].insertAdjacentHTML(
  40. 'afterend',
  41. `<a style="cursor: pointer;" href="${
  42. releaseProxy + resHref
  43. }">FastGit Download</a>`
  44. );
  45. }
  46. }
  47. }
  48. })();