Github加速clone

Github 加速 clone

  1. // ==UserScript==
  2. // @name Github加速clone
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Github 加速 clone
  6. // @author d1y
  7. // @match https://github.com/*
  8. // @grant none
  9. // @require https://cdn.bootcdn.net/ajax/libs/jquery/2.1.4/jquery.min.js
  10. // ==/UserScript==
  11.  
  12. (function () {
  13.  
  14. /**
  15. * 非盈利性质机构提供
  16. *
  17. * https://fastgit.org
  18. *
  19. * https://github.com/FastGitORG
  20. */
  21. const fastgithub_url = "https://hub.fastgit.org";
  22.  
  23. /*
  24. * 淘宝提供的镜像服务
  25. *
  26. * https://github.com/cnpm
  27. */
  28. let cnpmjs_url = "https://github.com.cnpmjs.org";
  29.  
  30. // url
  31. let url = window.location.href;
  32. let url_data = url.split("/");
  33. let github_auth_name = url_data[3];
  34. let git_name = url_data[4];
  35.  
  36. ;(function () {
  37. addCloneButton();
  38. addSiteButton();
  39. })()
  40.  
  41. /**
  42. * 添加镜像站点按钮
  43. */
  44. function addSiteButton() {
  45. const title = "淘宝镜像"
  46. let template = `
  47. <details class="get-repo-select-menu js-get-repo-select-menu position-relative details-overlay details-reset">
  48. <summary class="btn ml-2 btn-primary">
  49. <a href="${cnpmjs_url}/${github_auth_name}/${git_name}" style="color:#fff;">${title}</a>
  50. </summary>
  51. </details>
  52. `;
  53. $(".file-navigation").append(template);
  54. }
  55.  
  56. /**
  57. * 添加克隆按钮
  58. */
  59. function addCloneButton() {
  60. let template = `<span class="d-flex">
  61. <details class="get-repo-select-menu js-get-repo-select-menu position-relative details-overlay details-reset">
  62. <summary class="btn ml-2 btn-primary">
  63. 加速
  64. <span class="dropdown-caret"></span>
  65. </summary>
  66. <div class="position-relative">
  67. <div class="get-repo-modal dropdown-menu dropdown-menu-sw pb-0 js-toggler-container js-get-repo-modal p-3" style="width:352px;">
  68. <div class="get-repo-modal-options">
  69. <div class="clone-options https-clone-options">
  70. <h4 class="mb-1">
  71. 使用HTTPS克隆
  72. <a class="muted-link" href="https://docs.github.com/cn/github/using-git/which-remote-url-should-i-use" target="_blank" title="Which remote URL should I use?">
  73. <svg class="octicon octicon-question" viewBox="0 0 14 16" version="1.1" width="14" height="16" aria-hidden="true">
  74. <path fill-rule="evenodd" d="M6 10h2v2H6v-2zm4-3.5C10 8.64 8 9 8 9H6c0-.55.45-1 1-1h.5c.28 0 .5-.22.5-.5v-1c0-.28-.22-.5-.5-.5h-1c-.28 0-.5.22-.5.5V7H4c0-1.5 1.5-3 3-3s3 1 3 2.5zM7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 011.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7z"></path>
  75. </svg>
  76. </a>
  77. </h4>
  78. <p class="mb-2 get-repo-decription-text">
  79. CNPMJS.ORG加速通道
  80. </p>
  81. <div class="input-group mb-2">
  82. <input type="text" class="form-control input-monospace input-sm" data-autoselect="" value="${cnpmjs_url}/${github_auth_name}/${git_name}.git" readonly="">
  83. <div class="input-group-button">
  84. <clipboard-copy value="${cnpmjs_url}/${github_auth_name}/${git_name}.git" class="btn btn-sm" tabindex="0" role="button"><svg class="octicon octicon-clippy" viewBox="0 0 14 16" version="1.1" width="14" height="16" aria-hidden="true">
  85. <path fill-rule="evenodd" d="M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"></path>
  86. </svg>
  87. </clipboard-copy>
  88. </div>
  89. </div>
  90. <p class="mb-2 get-repo-decription-text">
  91. <a href="https://fastgit.org" target="_blank">FastGit.ORG</a>加速通道
  92. </p>
  93. <div class="input-group mb-2">
  94. <input type="text" class="form-control input-monospace input-sm" data-autoselect="" value="${fastgithub_url}/${github_auth_name}/${git_name}.git" readonly="">
  95. <div class="input-group-button">
  96. <clipboard-copy value="${fastgithub_url}/${github_auth_name}/${git_name}.git" class="btn btn-sm" tabindex="0" role="button"><svg class="octicon octicon-clippy" viewBox="0 0 14 16" version="1.1" width="14" height="16" aria-hidden="true">
  97. <path fill-rule="evenodd" d="M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"></path>
  98. </svg>
  99. </clipboard-copy>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </details>
  106. </span>`;
  107. $(".file-navigation").append(template);
  108. }
  109.  
  110. })();