|
3 | 3 | // @name:zh-CN Github 增强 - 高速下载 |
4 | 4 | // @name:zh-TW Github 增強 - 高速下載 |
5 | 5 | // @name:ru Улучшение GitHub – быстрое скачивание |
6 | | -// @version 2.6.22 |
| 6 | +// @version 2.6.23 |
7 | 7 | // @author X.I.U |
8 | 8 | // @description High-speed download of Git Clone/SSH, Release, Raw, Code(ZIP) and other files (Based on public welfare), project list file quick download (☁) |
9 | 9 | // @description:zh-CN 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件 (公益加速)、项目列表单文件快捷下载 (☁) |
|
34 | 34 |
|
35 | 35 | (function() { |
36 | 36 | 'use strict'; |
37 | | - var menu_rawFast = GM_getValue('xiu2_menu_raw_fast'), menu_rawFast_ID, menu_rawDownLink_ID, menu_gitClone_ID, menu_feedBack_ID; |
| 37 | + var menu_rawFast = GM_getValue('xiu2_menu_raw_fast'), menu_rawFast_ID, menu_rawDownLink_ID, menu_gitClone_ID, menu_customUrl_ID, menu_feedBack_ID; |
38 | 38 | const download_url_us = [ |
39 | 39 | ['https://gh.h233.eu.org/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [@X.I.U/XIU2] 提供'], |
40 | 40 | //['https://gh.api.99988866.xyz/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [hunshcn/gh-proxy] 提供'], // 官方演示站用的人太多了 |
|
184 | 184 | if (menu_rawFast == null){menu_rawFast = 1; GM_setValue('xiu2_menu_raw_fast', 1)}; |
185 | 185 | if (GM_getValue('menu_rawDownLink') == null){GM_setValue('menu_rawDownLink', true)}; |
186 | 186 | if (GM_getValue('menu_gitClone') == null){GM_setValue('menu_gitClone', true)}; |
| 187 | + // 如果自定义加速源不存在或为空则忽略,如果自定义加速源地址存在,则添加到 raw_url、clone_url 数组中 |
| 188 | + if (GM_getValue('custom_raw_url')) {raw_url.splice(1, 0, [GM_getValue('custom_raw_url'), '自定义', '[由你自定义的 Raw 加速源] 提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ #️⃣ 自定义加速源 ] 即可轮流设置 Raw、Git Clone、Release/Code(ZIP) 的自定义加速源地址(留空代表不设置)。'])}; |
| 189 | + if (GM_getValue('custom_clone_url')) {clone_url.unshift([GM_getValue('custom_clone_url'), '自定义', '[由你自定义的 Git Clone 加速源] 提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ #️⃣ 自定义加速源 ] 即可轮流设置 Raw、Git Clone、Release/Code(ZIP) 的自定义加速源地址(留空代表不设置)。'])}; |
187 | 190 | registerMenuCommand(); |
188 | 191 | // 注册脚本菜单 |
189 | 192 | function registerMenuCommand() { |
190 | 193 | // 如果反馈菜单ID不是 null,则删除所有脚本菜单 |
191 | | - if (menu_feedBack_ID) {GM_unregisterMenuCommand(menu_rawFast_ID); GM_unregisterMenuCommand(menu_rawDownLink_ID); GM_unregisterMenuCommand(menu_gitClone_ID); GM_unregisterMenuCommand(menu_feedBack_ID); menu_rawFast = GM_getValue('xiu2_menu_raw_fast');} |
| 194 | + if (menu_feedBack_ID) {GM_unregisterMenuCommand(menu_rawFast_ID); GM_unregisterMenuCommand(menu_rawDownLink_ID); GM_unregisterMenuCommand(menu_gitClone_ID); GM_unregisterMenuCommand(menu_customUrl_ID); GM_unregisterMenuCommand(menu_feedBack_ID); menu_rawFast = GM_getValue('xiu2_menu_raw_fast');} |
192 | 195 | // 避免在减少 raw 数组后,用户储存的数据大于数组而报错 |
193 | 196 | if (menu_rawFast > raw_url.length - 1) menu_rawFast = 0 |
194 | 197 | if (GM_getValue('menu_rawDownLink')) menu_rawFast_ID = GM_registerMenuCommand(`${['0️⃣','1️⃣','2️⃣','3️⃣','4️⃣','5️⃣','6️⃣','7️⃣','8️⃣','9️⃣','🔟'][menu_rawFast]} [ ${raw_url[menu_rawFast][1]} ] 加速源 (☁) - 点击切换`, menu_toggle_raw_fast); |
195 | 198 | menu_rawDownLink_ID = GM_registerMenuCommand(`${GM_getValue('menu_rawDownLink')?'✅':'❌'} 项目列表单文件快捷下载 (☁)`, function(){if (GM_getValue('menu_rawDownLink') == true) {GM_setValue('menu_rawDownLink', false); GM_notification({text: `已关闭 [项目列表单文件快捷下载 (☁)] 功能\n(点击刷新网页后生效)`, timeout: 3500, onclick: function(){location.reload();}});} else {GM_setValue('menu_rawDownLink', true); GM_notification({text: `已开启 [项目列表单文件快捷下载 (☁)] 功能\n(点击刷新网页后生效)`, timeout: 3500, onclick: function(){location.reload();}});}registerMenuCommand();}); |
196 | 199 | menu_gitClone_ID = GM_registerMenuCommand(`${GM_getValue('menu_gitClone')?'✅':'❌'} 添加 git clone 命令`, function(){if (GM_getValue('menu_gitClone') == true) {GM_setValue('menu_gitClone', false); GM_notification({text: `已关闭 [添加 git clone 命令] 功能\n(点击刷新网页后生效)`, timeout: 3500, onclick: function(){location.reload();}});} else {GM_setValue('menu_gitClone', true); GM_notification({text: `已开启 [添加 git clone 命令] 功能\n(点击刷新网页后生效)`, timeout: 3500, onclick: function(){location.reload();}});}registerMenuCommand();}); |
| 200 | + menu_customUrl_ID = GM_registerMenuCommand(`#️⃣ 自定义加速源`, function () { |
| 201 | + // 定义三种自定义加速源的键名和描述 |
| 202 | + const customKeys = [ |
| 203 | + { key: 'custom_raw_url', desc: 'Raw 加速源', placeholder: 'https://example.com/https://raw.githubusercontent.com' }, |
| 204 | + { key: 'custom_clone_url', desc: 'Git Clone 加速源', placeholder: 'https://example.com/https://github.com' }, |
| 205 | + { key: 'custom_download_url', desc: 'Release/Code(ZIP) 加速源', placeholder: 'https://example.com/https://github.com' } |
| 206 | + ]; |
| 207 | + // 递归弹出输入框 |
| 208 | + function promptCustomUrl(index = 0) { |
| 209 | + if (index >= customKeys.length) {GM_notification({ text: '自定义加速源设置已完成!\n(点击刷新网页后生效)', timeout: 3500, onclick: function () { location.reload(); } });return;} |
| 210 | + const { key, desc, placeholder } = customKeys[index]; |
| 211 | + let current = GM_getValue(key, ''); |
| 212 | + let input = prompt(`请输入自定义${desc}地址:\n- 当前:\n${current || '(未设置)'}\n\n- 示例:\n${placeholder}\n\n- 留空为不设置\n- 点击 [确定] 保存 并 继续设置下一个\n- 点击 [取消] 不保存 并 终止后续设置`,current); |
| 213 | + if (input !== null) {GM_setValue(key, input.trim());promptCustomUrl(index + 1);}// 如果用户点击 取消 按钮,则不再继续弹出 |
| 214 | + } |
| 215 | + promptCustomUrl(); |
| 216 | + }); |
197 | 217 | menu_feedBack_ID = GM_registerMenuCommand('💬 反馈 & 建议 [Github]', function () {window.GM_openInTab('https://github.com/XIU2/UserScript', {active: true,insert: true,setParent: true});window.GM_openInTab('https://greasyfork.org/zh-CN/scripts/412245/feedback', {active: true,insert: true,setParent: true});}); |
198 | 218 | } |
199 | 219 |
|
|
260 | 280 | // download_url 随机几个美国加速源 |
261 | 281 | function get_New_download_url() { |
262 | 282 | //return download_url_us // 全输出调试用 |
263 | | - let shuffled = download_url_us.slice(0), i = download_url_us.length, min = i - 6, temp, index; |
| 283 | + let minnum = 6; // 随机输出几个美国加速源 |
| 284 | + if (GM_getValue('custom_download_url')) {minnum = 5;} // 如果有自定义加速源,则只随机输出 5 个美国加速源 |
| 285 | + let shuffled = download_url_us.slice(0), i = download_url_us.length, min = i - minnum, temp, index; |
264 | 286 | while (i-- > min) {index = Math.floor((i + 1) * Math.random()); temp = shuffled[index]; shuffled[index] = shuffled[i]; shuffled[i] = temp;} |
265 | | - return shuffled.slice(min)//.concat(download_url); // 随机洗牌 download_url_us 数组并取前几个,然后将其合并至 download_url 数组 |
| 287 | + // 如果有自定义加速源,则将其添加到随机数组的开头 |
| 288 | + if (GM_getValue('custom_download_url')) {return [[GM_getValue('custom_download_url'), '自定义', '[由你自定义的 Release/Code(ZIP) 加速源地址] 提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ #️⃣ 自定义加速源 ] 即可轮流设置 Raw、Git Clone、Release/Code(ZIP) 的自定义加速源地址(留空代表不设置)。']].concat(shuffled.slice(min));} |
| 289 | + return shuffled.slice(min) // 随机洗牌 download_url_us 数组并取前几个,然后将其合并至 download_url 数组 |
266 | 290 | // 为了缓解非美国公益节点压力(考虑到很多人无视前面随机的美国节点),干脆也将其加入随机 |
267 | 291 | } |
268 | 292 |
|
|
0 commit comments