Github 镜像访问,加速下载

GitHub 镜像,github 加速

  1. // ==UserScript==
  2. // @name Github 镜像访问,加速下载
  3. // @icon https://github.githubassets.com/favicon.ico
  4. // @namespace https://github.com/jadezi/github-accelerator/
  5. // @version 2.0.9
  6. // @description GitHub 镜像,github 加速
  7. // @author jadezi、wuyuehui
  8. // @license GPL License
  9. // @match *://github.com/*
  10. // @require https://code.jquery.com/jquery-3.4.1.min.js
  11. // @resource customStyles https://gitee.com/jadezi/github-accelerator-css/raw/master/index.css
  12. // @grant GM_addStyle
  13. // @grant GM_setClipboard
  14. // @grant GM_getResourceText
  15. // @grant GM_getValue
  16. // @grant GM_setValue
  17. // @grant GM_registerMenuCommand
  18. // @grant GM_openInTab
  19. // ==/UserScript==
  20.  
  21. (function () {
  22. const clone_url_list = [
  23. {
  24. name: '地址1',
  25. url: 'https://kkgithub.com',
  26. },
  27. {
  28. name: '地址2',
  29. url: 'https://github.xiaohei.me',
  30. },
  31. ]
  32.  
  33. const download_url = [
  34. 'https://ghp.ci/',
  35. 'https://github.moeyy.xyz/',
  36. ]
  37.  
  38. function init() {
  39. initMirrorUrl()
  40. isProjectUrl()
  41. setTimeout(addDownload, 2000);
  42. addRelease()
  43. }
  44.  
  45. // Project页面不添加镜像面板
  46. function isProjectUrl(){
  47. const pathnameArr = window.location.pathname.split('/');
  48. if(pathnameArr.length>3&&pathnameArr[3]=="projects"){
  49. return
  50. }else{
  51. addPanel()
  52. }
  53. }
  54.  
  55. // 初始化镜像地址
  56. function initMirrorUrl() {
  57. const _clone_url_list = clone_url_list.map(mirrorItem => {
  58. const [clone_url, quick_look_url] = joinCloneMirrorUrl(mirrorItem)
  59. return {
  60. clone_url,
  61. quick_look_url,
  62. }
  63. })
  64. console.log('%c [ _clone_url_list ]', 'font-size:13px; background:pink; color:#bf2c9f;', _clone_url_list)
  65. GM_setValue('clone_url_list', _clone_url_list)
  66. }
  67.  
  68. // 拼接克隆地址
  69. const joinCloneMirrorUrl = (mirrorItem) => {
  70. const { url } = mirrorItem
  71. let commonUrl = ''
  72. commonUrl += "git clone ";
  73. commonUrl += url;
  74. const pathnameArr = window.location.pathname.split('/');
  75. let clone_url = commonUrl + '/' + pathnameArr[1] + '/' + pathnameArr[2] + '.git'
  76. let quick_look_url = url + '/' + pathnameArr[1] + '/' + pathnameArr[2]
  77. return [clone_url, quick_look_url]
  78. }
  79.  
  80. // 初始化镜像面板
  81. function addPanel() {
  82. const clone_url_list = GM_getValue('clone_url_list')
  83. // 镜像面板模板
  84. const mirror_template = `
  85. <div class="mirror-panel clearfix container-xl px-3 px-md-4 px-lg-5 mt-4">
  86. <div class="mb-1">
  87. <button class="btn btn-primary" type="button" id="mirror-btn">镜像网址</button>
  88. </div>
  89. <div class="collapse multi-collapse" id="collapse">
  90. <div class="user-card user-card-body">
  91. <div class="user-alert user-alert-danger" role="alert">镜像地址请不要登陆自己的账户,造成损失本人概不负责</div>
  92. <!-- 插入克隆模板列表位置 -->
  93. </div>
  94. </div>
  95. </div>
  96. `
  97. // 获取克隆地址模板
  98. const get_clone_template = (mirrorItem, index) => {
  99. const { clone_url, quick_look_url } = mirrorItem
  100. return `
  101. <div class="mb-3">
  102. <div class="h5 mb-1">克隆地址${index + 1}</div>
  103. <div class="input-group">
  104. <input type="text" class="form-control input-monospace input color-bg-subtle" value="${clone_url}"
  105. aria-label="${clone_url}">
  106. <div class="input-group-button">
  107. <clipboard-copy value="${clone_url}" aria-label="Copy to clipboard"
  108. class="btn js-clipboard-copy ClipboardButton" data-copy-feedback="Copied!" role="button" style="border-left:0;border-radius:0">
  109. 复制
  110. </clipboard-copy>
  111. </div>
  112. <div class="input-group-button">
  113. <button class="btn quick_look" type="button" data-url="${quick_look_url}" data class="btn">快速浏览</button>
  114. </div>
  115. </div>
  116. </div>
  117. `
  118. }
  119.  
  120. // 克隆模板数组
  121. const clone_template_List = clone_url_list.map((mirrorItem, index) => {
  122. return get_clone_template(mirrorItem, index)
  123. })
  124.  
  125. $(".repository-content").prepend(mirror_template);
  126.  
  127. clone_template_List.forEach(template => {
  128. $(".user-card-body").append(template);
  129. });
  130.  
  131. // 隐藏面板
  132. $("#mirror-btn").on("click", () => {
  133. togglePanelVisible()
  134. })
  135.  
  136. // 快速浏览
  137. $(".quick_look").on("click", (e) => {
  138. const quick_look_url = e.target.dataset.url
  139. window.open(quick_look_url)
  140. });
  141.  
  142. initPanelVisible()
  143. }
  144.  
  145. // 初始化镜像面板状态,根据上一次状态显示
  146. function initPanelVisible() {
  147. const currentPanelVisible = GM_getValue('panelVisible')
  148. if (currentPanelVisible === true) {
  149. $("#collapse").show();
  150. } else {
  151. $("#collapse").hide();
  152. }
  153. }
  154.  
  155. // Download ZIP
  156. // 功能已失效,等我有空了再来修复
  157. function addDownload() {
  158. const clone_url_list = GM_getValue('clone_url_list')
  159.  
  160. const get_download_template = (mirrorItem, index) => {
  161. const { quick_look_url } = mirrorItem
  162. let download_url = quick_look_url + "archive/refs/heads/master.zip";
  163. return `
  164. <li class="Box-row Box-row--hover-gray p-3 mt-0">
  165. <a class="d-flex flex-items-center color-fg-default text-bold no-underline" href=${download_url}>
  166. Fast Download ZIP(下载地址${index + 1})
  167. </a>
  168. </li>
  169. `
  170. }
  171.  
  172. const download_template_list = clone_url_list.map((mirrorItem, index) => {
  173. return get_download_template(mirrorItem, index)
  174. })
  175.  
  176. download_template_list.forEach(template => {
  177. $("#__primerPortalRoot__ > div > div > ul > div > ul").append(template)
  178. });
  179. }
  180.  
  181. // Release
  182. // 功能已失效,等我有空了再来修复
  183. function addRelease() {
  184. $(".Box.Box--condensed.mt-3").each(function () {
  185. $(this).find("li.Box-row").each(function () {
  186. const href = $(this).find("a")[0].href
  187. const li_obj= $(this)
  188. const download_url1 = `${download_url[0]}/${href}`
  189. const download_url2 = `${download_url[1]}/${href}`
  190. let download_template = `
  191. <div class="mt-1" style="height:17.5px;position: relative;top: -4px;left: 10px;margin-top:0px !important">
  192. <a class="btn btn-sm mr-1" style="line-height:17.5px" href="${download_url1}" rel="nofollow">快速下载1</a>
  193. <a class="btn btn-sm" href="${download_url2}" rel="nofollow">快速下载2</a>
  194. </div>
  195. `
  196. li_obj.find("#repo-content-pjax-container > div:nth-child(2) > div > div > div.Box-footer > div.mb-3 > details > div > div > ul > li:nth-child(2) > div.d-flex.flex-justify-start.col-12.col-lg-9").children().eq(0).before(download_template)
  197. });
  198. });
  199. }
  200.  
  201. // 切换面板显示隐藏
  202. function togglePanelVisible() {
  203. const currentPanelVisible = GM_getValue('panelVisible')
  204. if (currentPanelVisible === true) {
  205. $("#collapse").hide();
  206. } else {
  207. $("#collapse").show();
  208. }
  209. GM_setValue('panelVisible', !currentPanelVisible)
  210. }
  211.  
  212.  
  213. // 注册(不可用)菜单
  214. // GM_registerMenuCommand(`【🧲开启 & 关闭 - depth】`, toggleDepthVisible)
  215. GM_registerMenuCommand(`【🔔显示 & 隐藏 - 镜像信息面板】`, togglePanelVisible)
  216. GM_registerMenuCommand(`【📢意见 & 反馈】`, () => { window.GM_openInTab('https://github.com/jadezi/github-accelerator/issues/new', { active: true, insert: true, setParent: true }); })
  217.  
  218. // 设置自定义样式
  219. GM_addStyle(GM_getResourceText("customStyles"));
  220.  
  221. // 初始化
  222. init()
  223. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址