MCPcopy Create free account
hub / github.com/XIU2/UserScript / registerMenuCommand

Function registerMenuCommand

GithubEnhanced-High-Speed-Download.user.js:129–155  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127 registerMenuCommand();
128 // 注册脚本菜单
129 function registerMenuCommand() {
130 // 如果反馈菜单ID不是 null,则删除所有脚本菜单
131 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');}
132 // 避免在减少 raw 数组后,用户储存的数据大于数组而报错
133 if (menu_rawFast > raw_url.length - 1) menu_rawFast = 0
134 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);
135 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();});
136 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();});
137 menu_customUrl_ID = GM_registerMenuCommand(`#️⃣ 自定义加速源`, function () {
138 // 定义三种自定义加速源的键名和描述
139 const customKeys = [
140 { key: 'custom_raw_url', desc: 'Raw 加速源', placeholder: 'https://example.com/https://raw.githubusercontent.com' },
141 { key: 'custom_clone_url', desc: 'Git Clone 加速源', placeholder: 'https://example.com/https://github.com' },
142 { key: 'custom_download_url', desc: 'Release/Code(ZIP) 加速源', placeholder: 'https://example.com/https://github.com' }
143 ];
144 // 递归弹出输入框
145 function promptCustomUrl(index = 0) {
146 if (index >= customKeys.length) {GM_notification({ text: '自定义加速源设置已完成!\n(点击刷新网页后生效)', timeout: 3500, onclick: function () { location.reload(); } });return;}
147 const { key, desc, placeholder } = customKeys[index];
148 let current = GM_getValue(key, '');
149 let input = prompt(`请输入自定义${desc}地址:\n- 当前:\n${current || '(未设置)'}\n\n- 示例:\n${placeholder}\n\n- 留空为不设置\n- 点击 [确定] 保存 并 继续设置下一个\n- 点击 [取消] 不保存 并 终止后续设置`,current);
150 if (input !== null) {GM_setValue(key, input.trim());promptCustomUrl(index + 1);}// 如果用户点击 取消 按钮,则不再继续弹出
151 }
152 promptCustomUrl();
153 });
154 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});});
155 }
156
157 // 切换加速源
158 function menu_toggle_raw_fast() {

Calls 1

promptCustomUrlFunction · 0.85

Tested by

no test coverage detected