Skip to content

Commit 19a090d

Browse files
committed
新增 自定义加速源 功能(位于浏览器右上角 Tampermonkey 脚本菜单选项中,可自定义设置一个 Raw、Git Clone、Release/Code(ZIP) 加速源地址)
1 parent 37ee149 commit 19a090d

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

GithubEnhanced-High-Speed-Download.user.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @name:zh-CN Github 增强 - 高速下载
44
// @name:zh-TW Github 增強 - 高速下載
55
// @name:ru Улучшение GitHub – быстрое скачивание
6-
// @version 2.6.22
6+
// @version 2.6.23
77
// @author X.I.U
88
// @description High-speed download of Git Clone/SSH, Release, Raw, Code(ZIP) and other files (Based on public welfare), project list file quick download (☁)
99
// @description:zh-CN 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件 (公益加速)、项目列表单文件快捷下载 (☁)
@@ -34,7 +34,7 @@
3434

3535
(function() {
3636
'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;
3838
const download_url_us = [
3939
['https://gh.h233.eu.org/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [@X.I.U/XIU2] 提供'],
4040
//['https://gh.api.99988866.xyz/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [hunshcn/gh-proxy] 提供'], // 官方演示站用的人太多了
@@ -184,16 +184,36 @@
184184
if (menu_rawFast == null){menu_rawFast = 1; GM_setValue('xiu2_menu_raw_fast', 1)};
185185
if (GM_getValue('menu_rawDownLink') == null){GM_setValue('menu_rawDownLink', true)};
186186
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) 的自定义加速源地址(留空代表不设置)。'])};
187190
registerMenuCommand();
188191
// 注册脚本菜单
189192
function registerMenuCommand() {
190193
// 如果反馈菜单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');}
192195
// 避免在减少 raw 数组后,用户储存的数据大于数组而报错
193196
if (menu_rawFast > raw_url.length - 1) menu_rawFast = 0
194197
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);
195198
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();});
196199
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+
});
197217
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});});
198218
}
199219

@@ -260,9 +280,13 @@
260280
// download_url 随机几个美国加速源
261281
function get_New_download_url() {
262282
//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;
264286
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 数组
266290
// 为了缓解非美国公益节点压力(考虑到很多人无视前面随机的美国节点),干脆也将其加入随机
267291
}
268292

0 commit comments

Comments
 (0)