FastGit

GitHub Clone or download、releases 下载加速

目前為 2020-05-14 提交的版本,檢視 最新版本

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