diff --git a/GithubEnhanced-High-Speed-Download.user.js b/GithubEnhanced-High-Speed-Download.user.js index 3ba87f8..4156edf 100644 --- a/GithubEnhanced-High-Speed-Download.user.js +++ b/GithubEnhanced-High-Speed-Download.user.js @@ -3,9 +3,9 @@ // @name:zh-CN Github 增强 - 高速下载 // @name:zh-TW Github 增強 - 高速下載 // @name:en Github Enhancement - High Speed Download -// @version 2.2.2 +// @version 2.2.3 // @author X.I.U -// @description 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁) +// @description 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁)、添加 git clone 命令 // @description:zh-CN 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁) // @description:zh-TW 高速下載 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、項目列表單文件快捷下載 (☁) // @description:en High-speed download of Git Clone/SSH, Release, Raw, Code(ZIP) and other files, project list file quick download (☁) @@ -27,11 +27,11 @@ (function() { 'use strict'; - var backColor = '#ffffff', fontColor = '#888888', menu_raw_fast = GM_getValue('xiu2_menu_raw_fast'), menu_menu_raw_fast_ID, menu_feedBack_ID; + var backColor = '#ffffff', fontColor = '#888888', menu_rawFast = GM_getValue('xiu2_menu_raw_fast'), menu_rawFast_ID, menu_gitClone_ID, menu_feedBack_ID; const download_url_us = [ ['https://gh.gh2233.ml/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [@X.I.U/XIU2] 提供'], //['https://gh.api.99988866.xyz/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [hunshcn/gh-proxy] 提供'], // 官方演示站用的人太多了 - ['https://gh.ddlc.top/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [@mtr-static-official] 提供'], // 2023-01-14 + ['https://gh.ddlc.top/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [@mtr-static-official] 提供'], ['https://gh2.yanqishui.work/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [@HongjieCN] 提供'], ['https://ghdl.feizhuqwq.cf/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [feizhuqwq.com] 提供'], //['https://gh-proxy-misakano7545.koyeb.app/https://github.com', '美国', '[美国 Cloudflare CDN]'], @@ -89,38 +89,31 @@ '' ], 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);']; - if (menu_raw_fast == null){menu_raw_fast = 1; GM_setValue('xiu2_menu_raw_fast', 1)}; + if (menu_rawFast == null){menu_rawFast = 1; GM_setValue('xiu2_menu_raw_fast', 1)}; + if (GM_getValue('menu_gitClone') == null){GM_setValue('menu_gitClone', true)}; registerMenuCommand(); // 注册脚本菜单 function registerMenuCommand() { - if (menu_feedBack_ID) { // 如果反馈菜单ID不是 null,则删除所有脚本菜单 - GM_unregisterMenuCommand(menu_menu_raw_fast_ID); - GM_unregisterMenuCommand(menu_feedBack_ID); - menu_raw_fast = GM_getValue('xiu2_menu_raw_fast'); - } - if (menu_raw_fast > raw_url.length - 1) { // 避免在减少 raw 数组后,用户储存的数据大于数组而报错 - menu_raw_fast = 0 - } - menu_menu_raw_fast_ID = GM_registerMenuCommand(`${menu_num(menu_raw_fast)} [ ${raw_url[menu_raw_fast][1]} ] 加速源 (☁) - 点击切换`, menu_toggle_raw_fast); + // 如果反馈菜单ID不是 null,则删除所有脚本菜单 + if (menu_feedBack_ID) {GM_unregisterMenuCommand(menu_rawFast_ID); GM_unregisterMenuCommand(menu_gitClone_ID); GM_unregisterMenuCommand(menu_feedBack_ID); menu_rawFast = GM_getValue('xiu2_menu_raw_fast');} + // 避免在减少 raw 数组后,用户储存的数据大于数组而报错 + if (menu_rawFast > raw_url.length - 1) menu_rawFast = 0 + 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); + 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();}); 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});}); } // 切换加速源 function menu_toggle_raw_fast() { // 如果当前加速源位置大于等于加速源总数,则改为第一个加速源,反之递增下一个加速源 - if (menu_raw_fast >= raw_url.length - 1) {menu_raw_fast = 0;} else {menu_raw_fast += 1;} - GM_setValue('xiu2_menu_raw_fast', menu_raw_fast); + if (menu_rawFast >= raw_url.length - 1) {menu_rawFast = 0;} else {menu_rawFast += 1;} + GM_setValue('xiu2_menu_raw_fast', menu_rawFast); delRawDownLink(); // 删除旧加速源 addRawDownLink(); // 添加新加速源 - GM_notification({text: "已切换加速源为:" + raw_url[menu_raw_fast][1], timeout: 3000}); // 提示消息 + GM_notification({text: "已切换加速源为:" + raw_url[menu_rawFast][1], timeout: 3000}); // 提示消息 registerMenuCommand(); // 重新注册脚本菜单 }; - // 菜单数字图标 - function menu_num(num) { - return ['0️⃣','1️⃣','2️⃣','3️⃣','4️⃣','5️⃣','6️⃣','7️⃣','8️⃣','9️⃣','🔟'][num] - } - colorMode(); // 适配白天/夜间主题模式 if (location.pathname.indexOf('/releases')) addRelease(); // Release 加速 setTimeout(addDownloadZIP, 2000); // Download ZIP 加速 @@ -200,7 +193,7 @@ function addDownloadZIP() { if (document.querySelector('.XIU2-DZ')) return let html = document.querySelector('#local-panel ul li:last-child');if (!html) return - let href = html.getElementsByTagName('a')[0].href, + let href = html.firstElementChild.href, url = '', _html = '', new_download_url = get_New_download_url(); for (let i=0;i
${svg[1]}
` + _html += `
${svg[1]}
` } html.insertAdjacentHTML('afterend', _html); } @@ -240,13 +234,14 @@ function addGitCloneSSH() { if (document.querySelector('.XIU2-GCS')) return let html = document.querySelector('[role="tabpanel"]:nth-child(3) div.input-group');if (!html) return - let href_split = html.getElementsByTagName('input')[0].getAttribute('value').split(':'), - _html = ''; + let href_split = html.firstElementChild.value.split(':'), + _html = '', _gitClone = ''; if (href_split[0] != 'git@github.com') return + if (GM_getValue('menu_gitClone')) {_gitClone='git clone '; html.firstElementChild.value = _gitClone + html.firstElementChild.value;} for (let i=0;i
${svg[1]}
` + _html += `
${svg[1]}
` } html.insertAdjacentHTML('afterend', _html); } @@ -304,14 +299,14 @@ Name = cntElm_a.innerText, href = cntElm_a.getAttribute('href'), href2 = href.replace('/blob/','/'), url, url_name, url_tip = ''; - if ((raw_url[menu_raw_fast][0].indexOf('/gh') + 3 === raw_url[menu_raw_fast][0].length) && raw_url[menu_raw_fast][0].indexOf('cdn.staticaly.com') === -1) { - url = raw_url[menu_raw_fast][0] + href.replace('/blob/','@'); + if ((raw_url[menu_rawFast][0].indexOf('/gh') + 3 === raw_url[menu_rawFast][0].length) && raw_url[menu_rawFast][0].indexOf('cdn.staticaly.com') === -1) { + url = raw_url[menu_rawFast][0] + href.replace('/blob/','@'); } else { - url = raw_url[menu_raw_fast][0] + href2; + url = raw_url[menu_rawFast][0] + href2; } - url_name = raw_url[menu_raw_fast][1]; url_tip = raw_url[menu_raw_fast][2]; - cntElm_svg.insertAdjacentHTML('afterend', ``); + url_name = raw_url[menu_rawFast][1]; url_tip = raw_url[menu_rawFast][2]; + cntElm_svg.insertAdjacentHTML('afterend', ``); // 绑定鼠标事件 trElm.onmouseover = mouseOverHandler; trElm.onmouseout = mouseOutHandler; @@ -366,17 +361,17 @@ if (document.getElementById('XIU2-Github')) {style_Add = document.getElementById('XIU2-Github')} else {style_Add = document.createElement('style'); style_Add.id = 'XIU2-Github'; style_Add.type = 'text/css';} backColor = '#ffffff'; fontColor = '#888888'; - if (document.getElementsByTagName('html')[0].getAttribute('data-color-mode') === 'dark') { // 如果是夜间模式 - if (document.getElementsByTagName('html')[0].getAttribute('data-dark-theme') === 'dark_dimmed') { + if (document.lastElementChild.dataset.colorMode === 'dark') { // 如果是夜间模式 + if (document.lastElementChild.dataset.darkTheme === 'dark_dimmed') { backColor = '#272e37'; fontColor = '#768390'; } else { backColor = '#161a21'; fontColor = '#97a0aa'; } - } else if (document.getElementsByTagName('html')[0].getAttribute('data-color-mode') === 'auto') { // 如果是自动模式 - if (window.matchMedia('(prefers-color-scheme: dark)').matches || document.getElementsByTagName('html')[0].getAttribute('data-light-theme').indexOf('dark') > -1) { // 如果浏览器是夜间模式 或 白天模式是 dark 的情况 - if (document.getElementsByTagName('html')[0].getAttribute('data-dark-theme') === 'dark_dimmed') { + } else if (document.lastElementChild.dataset.colorMode === 'auto') { // 如果是自动模式 + if (window.matchMedia('(prefers-color-scheme: dark)').matches || document.lastElementChild.dataset.lightTheme.indexOf('dark') > -1) { // 如果浏览器是夜间模式 或 白天模式是 dark 的情况 + if (document.lastElementChild.dataset.darkTheme === 'dark_dimmed') { backColor = '#272e37'; fontColor = '#768390'; - } else if (document.getElementsByTagName('html')[0].getAttribute('data-dark-theme').indexOf('light') == -1) { // 排除夜间模式是 light 的情况 + } else if (document.lastElementChild.dataset.darkTheme.indexOf('light') == -1) { // 排除夜间模式是 light 的情况 backColor = '#161a21'; fontColor = '#97a0aa'; } }