FastGit

GitHub Clone or download、Releases 下载加速

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

  1. // ==UserScript==
  2. // @name FastGit
  3. // @version 0.7
  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.06.30_V0.7 修改 Releases 下载接口
  13. // @note 2020.06.29_V0.6 Releases 界面点击文件体积下载,不支持 Source code 下载
  14. // @note 2020.06.27_V0.5 适配新版 UI
  15. // @note 2020.05.06_V0.4 新增: zipProxy - zip 下载链接
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. 'use strict';
  20. var gitProxy = 'https://hub.fastgit.org';
  21. var sshProxy = 'git@fastgit.org';
  22. var releaseProxy = 'https://download.fastgit.org';
  23.  
  24. if (window.location.href.indexOf('releases') === -1) {
  25. var regex = /"((\/.*)+\.zip)"/;
  26. var domDownload = document.querySelector('span.d-flex')||document.querySelector('get-repo-controller');
  27. if (domDownload !== null) {
  28. var oldHtml = domDownload.outerHTML;
  29. var zipLink = gitProxy + regex.exec(oldHtml)[1];
  30. var outHtml = oldHtml
  31. .replace('Clone or download', 'FastGit')
  32. .replace('Clone', 'FastGit')
  33. .replace(/https:\/\/github.com/g, gitProxy)
  34. .replace(regex, zipLink)
  35. .replace(/git@github.com/g, sshProxy)
  36. .replace('https%3A%2F%2Fgithub.com', 'https%3A%2F%2Fhub.fastgit.org');
  37.  
  38. domDownload.insertAdjacentHTML('afterend', outHtml);
  39. }
  40. } else {
  41. var resDownload = document.querySelectorAll('.Box--condensed small');
  42. if (resDownload !== null) {
  43. var i;
  44. for (i = 0; i < resDownload.length; i++) {
  45. var resHref = resDownload[i].previousElementSibling.getAttribute('href');
  46. var size = resDownload[i].textContent;
  47. resDownload[i].textContent = "";
  48. resDownload[i].insertAdjacentHTML(
  49. 'beforeend',
  50. `<a style="cursor: pointer;" title="FastGit Download" href="${
  51. releaseProxy + resHref
  52. }">${size}</a>`
  53. );
  54. }
  55. }
  56. }
  57. })();