Github releases mirror

github releases高速下载按钮

  1. // ==UserScript==
  2. // @name Github releases mirror
  3. // @version 2.5.0
  4. // @author X.I.U
  5. // @description github releases高速下载按钮
  6. // @description:en High-speed download of Release
  7. // @match *://github.com/*
  8. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAACEUExURUxpcRgWFhsYGBgWFhcWFh8WFhoYGBgWFiUlJRcVFRkWFhgVFRgWFhgVFRsWFhgWFigeHhkWFv////////////r6+h4eHv///xcVFfLx8SMhIUNCQpSTk/r6+jY0NCknJ97e3ru7u+fn51BOTsPCwqGgoISDg6empmpoaK2srNDQ0FhXV3eXcCcAAAAXdFJOUwCBIZXMGP70BuRH2Ze/LpIMUunHkpQR34sfygAAAVpJREFUOMt1U+magjAMDAVb5BDU3W25b9T1/d9vaYpQKDs/rF9nSNJkArDA9ezQZ8wPbc8FE6eAiQUsOO1o19JolFibKCdHGHC0IJezOMD5snx/yE+KOYYr42fPSufSZyazqDoseTPw4lGJNOu6LBXVUPBG3lqYAOv/5ZwnNUfUifzBt8gkgfgINmjxOpgqUA147QWNaocLniqq3QsSVbQHNp45N/BAwoYQz9oUJEiE4GMGfoBSMj5gjeWRIMMqleD/CAzUHFqTLyjOA5zjNnwa4UCEZ2YK3khEcBXHjVBtEFeIZ6+NxYbPqWp1DLKV42t6Ujn2ydyiPi9nX0TTNAkVVZ/gozsl6FbrktkwaVvL2TRK0C8Ca7Hck7f5OBT6FFbLATkL2ugV0tm0RLM9fedDvhWstl8Wp9AFDjFX7yOY/lJrv8AkYuz7fuP8dv9izCYH+x3/LBnj9fYPBTpJDNzX+7cAAAAASUVORK5CYII=
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_unregisterMenuCommand
  11. // @grant GM_openInTab
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant GM_notification
  15. // @grant window.onurlchange
  16. // @sandbox JavaScript
  17. // @license GPL-3.0 License
  18. // @run-at document-end
  19. // @namespace https://gf.qytechs.cn/scripts/412245
  20. // @supportURL https://github.com/XIU2/UserScript
  21. // @homepageURL https://github.com/XIU2/UserScript
  22. // ==/UserScript==
  23.  
  24. (function() {
  25. 'use strict';
  26. var backColor = '#ffffff', fontColor = '#888888';
  27. const download_url = [
  28. ['https://dl.moapp.me/https://github.com', 'motrix镜像', '项目地址:
https://motrix.app/']
  29. ], style = ['padding:0 6px; margin-right: -1px; border-radius: 2px; background-color: var(--XIU2-back-Color); border-color: rgba(27, 31, 35, 0.1); font-size: 11px; color: var(--XIU2-font-Color);'];
  30. const mirror_num = 3 //镜像个数
  31. // Tampermonkey v4.11 版本添加的 onurlchange 事件 grant,可以监控 pjax 等网页的 URL 变化
  32. if (window.onurlchange === undefined) addUrlChangeEvent();
  33.  
  34. var check_show = function(){
  35. if (location.pathname.indexOf('releases') > -1) {
  36. addRelease();
  37. }
  38. };
  39. window.addEventListener('urlchange', check_show);
  40.  
  41. // Github Git Clone/SSH、Release、Download ZIP 改版为动态加载文件列表,因此需要监控网页元素变化
  42. const observer = new MutationObserver(check_show);
  43. observer.observe(document, { childList: true, subtree: true });
  44.  
  45. // download_url 随机 n 个加速源
  46. function get_New_download_url() {
  47. if (download_url.length < mirror_num) return download_url;
  48. let shuffled = download_url.slice(0), i = download_url.length, min = i - mirror_num, temp, index;
  49. while (i-- > min) {index = Math.floor((i + 1) * Math.random()); temp = shuffled[index]; shuffled[index] = shuffled[i]; shuffled[i] = temp;}
  50. return shuffled.slice(min); // 随机洗牌 download_url 数组并取前 n 个
  51. }
  52.  
  53. // Release
  54. function addRelease() {
  55. let html = document.querySelectorAll('.Box-footer'); if (html.length == 0 || location.pathname.indexOf('/releases') == -1) return
  56. let divDisplay = 'margin-left: -90px;', new_download_url = get_New_download_url();
  57. if (document.documentElement.clientWidth > 755) {divDisplay = 'margin-top: -3px;margin-left: 8px;display: inherit;';}; // 调整小屏幕时的样式
  58. for (const current of html) {
  59. if (current.querySelector('.XIU2-RS')) continue
  60. current.querySelectorAll('li.Box-row a').forEach(function (_this) {
  61. let href = _this.href.split(location.host),
  62. url = '', _html = `<div class="XIU2-RS" style="${divDisplay}">`;
  63.  
  64. for (let i=0;i<new_download_url.length;i++) {
  65. if (new_download_url[i][3] !== undefined && url.indexOf('/archive/') !== -1) {
  66. url = new_download_url[i][3] + href[1]
  67. } else {
  68. url = new_download_url[i][0] + href[1]
  69. }
  70. if (location.host !== 'github.com') url = url.replace(location.host,'github.com')
  71. _html += `<a style="${style[0]}" class="btn" href="${url}" title="${new_download_url[i][2]}" rel="noreferrer noopener nofollow">${new_download_url[i][1]}</a>`;
  72. }
  73. _this.parentElement.nextElementSibling.insertAdjacentHTML('beforeend', _html + '</div>');
  74. });
  75. }
  76. }
  77.  
  78.  
  79. // 自定义 urlchange 事件(用来监听 URL 变化),针对非 Tampermonkey 油猴管理器
  80. function addUrlChangeEvent() {
  81. history.pushState = ( f => function pushState(){
  82. var ret = f.apply(this, arguments);
  83. window.dispatchEvent(new Event('pushstate'));
  84. window.dispatchEvent(new Event('urlchange'));
  85. return ret;
  86. })(history.pushState);
  87.  
  88. history.replaceState = ( f => function replaceState(){
  89. var ret = f.apply(this, arguments);
  90. window.dispatchEvent(new Event('replacestate'));
  91. window.dispatchEvent(new Event('urlchange'));
  92. return ret;
  93. })(history.replaceState);
  94.  
  95. window.addEventListener('popstate',()=>{ // 点击浏览器的前进/后退按钮时触发 urlchange 事件
  96. window.dispatchEvent(new Event('urlchange'))
  97. });
  98. }
  99. })();

QingJ © 2025

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