|
3 | 3 | // @name:zh-CN Github 增强 - 高速下载 |
4 | 4 | // @name:zh-TW Github 增強 - 高速下載 |
5 | 5 | // @name:en Github Enhancement - High Speed Download |
6 | | -// @version 2.2.2 |
| 6 | +// @version 2.2.3 |
7 | 7 | // @author X.I.U |
8 | | -// @description 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁) |
| 8 | +// @description 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁)、添加 git clone 命令 |
9 | 9 | // @description:zh-CN 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁) |
10 | 10 | // @description:zh-TW 高速下載 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、項目列表單文件快捷下載 (☁) |
11 | 11 | // @description:en High-speed download of Git Clone/SSH, Release, Raw, Code(ZIP) and other files, project list file quick download (☁) |
|
27 | 27 |
|
28 | 28 | (function() { |
29 | 29 | 'use strict'; |
30 | | - var backColor = '#ffffff', fontColor = '#888888', menu_raw_fast = GM_getValue('xiu2_menu_raw_fast'), menu_menu_raw_fast_ID, menu_feedBack_ID; |
| 30 | + var backColor = '#ffffff', fontColor = '#888888', menu_rawFast = GM_getValue('xiu2_menu_raw_fast'), menu_rawFast_ID, menu_gitClone_ID, menu_feedBack_ID; |
31 | 31 | const download_url_us = [ |
32 | 32 | ['https://gh.gh2233.ml/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [@X.I.U/XIU2] 提供'], |
33 | 33 | //['https://gh.api.99988866.xyz/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [hunshcn/gh-proxy] 提供'], // 官方演示站用的人太多了 |
34 | | - ['https://gh.ddlc.top/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [@mtr-static-official] 提供'], // 2023-01-14 |
| 34 | + ['https://gh.ddlc.top/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [@mtr-static-official] 提供'], |
35 | 35 | ['https://gh2.yanqishui.work/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [@HongjieCN] 提供'], |
36 | 36 | ['https://ghdl.feizhuqwq.cf/https://github.com', '美国', '[美国 Cloudflare CDN] - 该公益加速源由 [feizhuqwq.com] 提供'], |
37 | 37 | //['https://gh-proxy-misakano7545.koyeb.app/https://github.com', '美国', '[美国 Cloudflare CDN]'], |
|
89 | 89 | '<svg class="octicon octicon-cloud-download" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M9 12h2l-3 3-3-3h2V7h2v5zm3-8c0-.44-.91-3-4.5-3C5.08 1 3 2.92 3 5 1.02 5 0 6.52 0 8c0 1.53 1 3 3 3h3V9.7H3C1.38 9.7 1.3 8.28 1.3 8c0-.17.05-1.7 1.7-1.7h1.3V5c0-1.39 1.56-2.7 3.2-2.7 2.55 0 3.13 1.55 3.2 1.8v1.2H12c.81 0 2.7.22 2.7 2.2 0 2.09-2.25 2.2-2.7 2.2h-2V11h2c2.08 0 4-1.16 4-3.5C16 5.06 14.08 4 12 4z"></path></svg>' |
90 | 90 | ], 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);']; |
91 | 91 |
|
92 | | - if (menu_raw_fast == null){menu_raw_fast = 1; GM_setValue('xiu2_menu_raw_fast', 1)}; |
| 92 | + if (menu_rawFast == null){menu_rawFast = 1; GM_setValue('xiu2_menu_raw_fast', 1)}; |
| 93 | + if (GM_getValue('menu_gitClone') == null){GM_setValue('menu_gitClone', true)}; |
93 | 94 | registerMenuCommand(); |
94 | 95 | // 注册脚本菜单 |
95 | 96 | function registerMenuCommand() { |
96 | | - if (menu_feedBack_ID) { // 如果反馈菜单ID不是 null,则删除所有脚本菜单 |
97 | | - GM_unregisterMenuCommand(menu_menu_raw_fast_ID); |
98 | | - GM_unregisterMenuCommand(menu_feedBack_ID); |
99 | | - menu_raw_fast = GM_getValue('xiu2_menu_raw_fast'); |
100 | | - } |
101 | | - if (menu_raw_fast > raw_url.length - 1) { // 避免在减少 raw 数组后,用户储存的数据大于数组而报错 |
102 | | - menu_raw_fast = 0 |
103 | | - } |
104 | | - menu_menu_raw_fast_ID = GM_registerMenuCommand(`${menu_num(menu_raw_fast)} [ ${raw_url[menu_raw_fast][1]} ] 加速源 (☁) - 点击切换`, menu_toggle_raw_fast); |
| 97 | + // 如果反馈菜单ID不是 null,则删除所有脚本菜单 |
| 98 | + 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');} |
| 99 | + // 避免在减少 raw 数组后,用户储存的数据大于数组而报错 |
| 100 | + if (menu_rawFast > raw_url.length - 1) menu_rawFast = 0 |
| 101 | + 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); |
| 102 | + 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();}); |
105 | 103 | 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});}); |
106 | 104 | } |
107 | 105 |
|
108 | 106 | // 切换加速源 |
109 | 107 | function menu_toggle_raw_fast() { |
110 | 108 | // 如果当前加速源位置大于等于加速源总数,则改为第一个加速源,反之递增下一个加速源 |
111 | | - if (menu_raw_fast >= raw_url.length - 1) {menu_raw_fast = 0;} else {menu_raw_fast += 1;} |
112 | | - GM_setValue('xiu2_menu_raw_fast', menu_raw_fast); |
| 109 | + if (menu_rawFast >= raw_url.length - 1) {menu_rawFast = 0;} else {menu_rawFast += 1;} |
| 110 | + GM_setValue('xiu2_menu_raw_fast', menu_rawFast); |
113 | 111 | delRawDownLink(); // 删除旧加速源 |
114 | 112 | addRawDownLink(); // 添加新加速源 |
115 | | - GM_notification({text: "已切换加速源为:" + raw_url[menu_raw_fast][1], timeout: 3000}); // 提示消息 |
| 113 | + GM_notification({text: "已切换加速源为:" + raw_url[menu_rawFast][1], timeout: 3000}); // 提示消息 |
116 | 114 | registerMenuCommand(); // 重新注册脚本菜单 |
117 | 115 | }; |
118 | 116 |
|
119 | | - // 菜单数字图标 |
120 | | - function menu_num(num) { |
121 | | - return ['0️⃣','1️⃣','2️⃣','3️⃣','4️⃣','5️⃣','6️⃣','7️⃣','8️⃣','9️⃣','🔟'][num] |
122 | | - } |
123 | | - |
124 | 117 | colorMode(); // 适配白天/夜间主题模式 |
125 | 118 | if (location.pathname.indexOf('/releases')) addRelease(); // Release 加速 |
126 | 119 | setTimeout(addDownloadZIP, 2000); // Download ZIP 加速 |
|
200 | 193 | function addDownloadZIP() { |
201 | 194 | if (document.querySelector('.XIU2-DZ')) return |
202 | 195 | let html = document.querySelector('#local-panel ul li:last-child');if (!html) return |
203 | | - let href = html.getElementsByTagName('a')[0].href, |
| 196 | + let href = html.firstElementChild.href, |
204 | 197 | url = '', _html = '', new_download_url = get_New_download_url(); |
205 | 198 | for (let i=0;i<new_download_url.length;i++) { |
206 | 199 | if (new_download_url[i][3] === '') continue |
|
221 | 214 | function addGitClone() { |
222 | 215 | if (document.querySelector('.XIU2-GC')) return |
223 | 216 | let html = document.querySelector('[role="tabpanel"]:nth-child(2) div.input-group');if (!html) return |
224 | | - let href_split = html.getElementsByTagName('input')[0].getAttribute('value').split(location.host), |
225 | | - url = '', _html = ''; |
| 217 | + let href_split = html.firstElementChild.value.split(location.host), |
| 218 | + url = '', _html = '', _gitClone = ''; |
226 | 219 |
|
| 220 | + if (GM_getValue('menu_gitClone')) {_gitClone='git clone '; html.firstElementChild.value = _gitClone + html.firstElementChild.value;} |
227 | 221 | for (let i=0;i<clone_url.length;i++) { |
228 | 222 | if (clone_url[i][0] === 'https://gitclone.com') { |
229 | 223 | url = clone_url[i][0] + '/github.com' + href_split[1] |
230 | 224 | } else { |
231 | 225 | url = clone_url[i][0] + href_split[1] |
232 | 226 | } |
233 | | - _html += `<div class="input-group XIU2-GC" style="margin-top: 4px;" title="加速源:${clone_url[i][1]} (点击可直接复制)"><input value="${url}" aria-label="${url}" title="${clone_url[i][2]}" type="text" class="form-control input-monospace input-sm color-bg-subtle" data-autoselect="" readonly=""><div class="input-group-button"><clipboard-copy value="${url}" aria-label="Copy to clipboard" class="btn btn-sm js-clipboard-copy tooltipped-no-delay ClipboardButton" tabindex="0" role="button">${svg[1]}</clipboard-copy></div></div>` |
| 227 | + _html += `<div class="input-group XIU2-GC" style="margin-top: 4px;" title="加速源:${clone_url[i][1]} (点击可直接复制)"><input value="${_gitClone}${url}" aria-label="${url}" title="${clone_url[i][2]}" type="text" class="form-control input-monospace input-sm color-bg-subtle" data-autoselect="" readonly=""><div class="input-group-button"><clipboard-copy value="${_gitClone}${url}" aria-label="Copy to clipboard" class="btn btn-sm js-clipboard-copy tooltipped-no-delay ClipboardButton" tabindex="0" role="button">${svg[1]}</clipboard-copy></div></div>` |
234 | 228 | } |
235 | 229 | html.insertAdjacentHTML('afterend', _html); |
236 | 230 | } |
|
240 | 234 | function addGitCloneSSH() { |
241 | 235 | if (document.querySelector('.XIU2-GCS')) return |
242 | 236 | let html = document.querySelector('[role="tabpanel"]:nth-child(3) div.input-group');if (!html) return |
243 | | - let href_split = html.getElementsByTagName('input')[0].getAttribute('value').split(':'), |
244 | | - _html = ''; |
| 237 | + let href_split = html.firstElementChild.value.split(':'), |
| 238 | + _html = '', _gitClone = ''; |
245 | 239 |
|
246 | 240 | if (href_split[0] != 'git@github.com') return |
247 | 241 |
|
| 242 | + if (GM_getValue('menu_gitClone')) {_gitClone='git clone '; html.firstElementChild.value = _gitClone + html.firstElementChild.value;} |
248 | 243 | for (let i=0;i<clone_ssh_url.length;i++) { |
249 | | - _html += `<div class="input-group XIU2-GCS" style="margin-top: 4px;" title="加速源:${clone_ssh_url[i][1]} (点击可直接复制)"><input value="${clone_ssh_url[i][0] + ':' + href_split[1]}" aria-label="${clone_ssh_url[i][0] + ':' + href_split[1]}" title="${clone_ssh_url[i][2]}" type="text" class="form-control input-monospace input-sm color-bg-subtle" data-autoselect="" readonly=""><div class="input-group-button"><clipboard-copy value="${clone_ssh_url[i][0] + ':' + href_split[1]}" aria-label="Copy to clipboard" class="btn btn-sm js-clipboard-copy tooltipped-no-delay ClipboardButton" tabindex="0" role="button">${svg[1]}</clipboard-copy></div></div>` |
| 244 | + _html += `<div class="input-group XIU2-GCS" style="margin-top: 4px;" title="加速源:${clone_ssh_url[i][1]} (点击可直接复制)"><input value="${_gitClone}${clone_ssh_url[i][0] + ':' + href_split[1]}" aria-label="${clone_ssh_url[i][0] + ':' + href_split[1]}" title="${clone_ssh_url[i][2]}" type="text" class="form-control input-monospace input-sm color-bg-subtle" data-autoselect="" readonly=""><div class="input-group-button"><clipboard-copy value="${_gitClone}${clone_ssh_url[i][0] + ':' + href_split[1]}" aria-label="Copy to clipboard" class="btn btn-sm js-clipboard-copy tooltipped-no-delay ClipboardButton" tabindex="0" role="button">${svg[1]}</clipboard-copy></div></div>` |
250 | 245 | } |
251 | 246 | html.insertAdjacentHTML('afterend', _html); |
252 | 247 | } |
|
304 | 299 | Name = cntElm_a.innerText, |
305 | 300 | href = cntElm_a.getAttribute('href'), |
306 | 301 | href2 = href.replace('/blob/','/'), url, url_name, url_tip = ''; |
307 | | - 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) { |
308 | | - url = raw_url[menu_raw_fast][0] + href.replace('/blob/','@'); |
| 302 | + 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) { |
| 303 | + url = raw_url[menu_rawFast][0] + href.replace('/blob/','@'); |
309 | 304 | } else { |
310 | | - url = raw_url[menu_raw_fast][0] + href2; |
| 305 | + url = raw_url[menu_rawFast][0] + href2; |
311 | 306 | } |
312 | 307 |
|
313 | | - url_name = raw_url[menu_raw_fast][1]; url_tip = raw_url[menu_raw_fast][2]; |
314 | | - cntElm_svg.insertAdjacentHTML('afterend', `<a href="${url}" download="${Name}" target="_blank" rel="noreferrer noopener nofollow" class="fileDownLink" style="display: none;" title="「${url_name}」 [Alt + 左键] 或 [右键 - 另存为...] 下载文件。 注意:鼠标点击 [☁] 图标,而不是左侧的文件名! ${url_tip}提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ ${raw_url[menu_raw_fast][1]} ] 加速源 (☁) 即可切换。">${svg[2]}</a>`); |
| 308 | + url_name = raw_url[menu_rawFast][1]; url_tip = raw_url[menu_rawFast][2]; |
| 309 | + cntElm_svg.insertAdjacentHTML('afterend', `<a href="${url}" download="${Name}" target="_blank" rel="noreferrer noopener nofollow" class="fileDownLink" style="display: none;" title="「${url_name}」 [Alt + 左键] 或 [右键 - 另存为...] 下载文件。 注意:鼠标点击 [☁] 图标,而不是左侧的文件名! ${url_tip}提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ ${raw_url[menu_rawFast][1]} ] 加速源 (☁) 即可切换。">${svg[2]}</a>`); |
315 | 310 | // 绑定鼠标事件 |
316 | 311 | trElm.onmouseover = mouseOverHandler; |
317 | 312 | trElm.onmouseout = mouseOutHandler; |
|
366 | 361 | 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';} |
367 | 362 | backColor = '#ffffff'; fontColor = '#888888'; |
368 | 363 |
|
369 | | - if (document.getElementsByTagName('html')[0].getAttribute('data-color-mode') === 'dark') { // 如果是夜间模式 |
370 | | - if (document.getElementsByTagName('html')[0].getAttribute('data-dark-theme') === 'dark_dimmed') { |
| 364 | + if (document.lastElementChild.dataset.colorMode === 'dark') { // 如果是夜间模式 |
| 365 | + if (document.lastElementChild.dataset.darkTheme === 'dark_dimmed') { |
371 | 366 | backColor = '#272e37'; fontColor = '#768390'; |
372 | 367 | } else { |
373 | 368 | backColor = '#161a21'; fontColor = '#97a0aa'; |
374 | 369 | } |
375 | | - } else if (document.getElementsByTagName('html')[0].getAttribute('data-color-mode') === 'auto') { // 如果是自动模式 |
376 | | - if (window.matchMedia('(prefers-color-scheme: dark)').matches || document.getElementsByTagName('html')[0].getAttribute('data-light-theme').indexOf('dark') > -1) { // 如果浏览器是夜间模式 或 白天模式是 dark 的情况 |
377 | | - if (document.getElementsByTagName('html')[0].getAttribute('data-dark-theme') === 'dark_dimmed') { |
| 370 | + } else if (document.lastElementChild.dataset.colorMode === 'auto') { // 如果是自动模式 |
| 371 | + if (window.matchMedia('(prefers-color-scheme: dark)').matches || document.lastElementChild.dataset.lightTheme.indexOf('dark') > -1) { // 如果浏览器是夜间模式 或 白天模式是 dark 的情况 |
| 372 | + if (document.lastElementChild.dataset.darkTheme === 'dark_dimmed') { |
378 | 373 | backColor = '#272e37'; fontColor = '#768390'; |
379 | | - } else if (document.getElementsByTagName('html')[0].getAttribute('data-dark-theme').indexOf('light') == -1) { // 排除夜间模式是 light 的情况 |
| 374 | + } else if (document.lastElementChild.dataset.darkTheme.indexOf('light') == -1) { // 排除夜间模式是 light 的情况 |
380 | 375 | backColor = '#161a21'; fontColor = '#97a0aa'; |
381 | 376 | } |
382 | 377 | } |
|
0 commit comments