diff --git a/GithubEnhanced-High-Speed-Download.user.js b/GithubEnhanced-High-Speed-Download.user.js index 1b4d1e4..b302a8f 100644 --- a/GithubEnhanced-High-Speed-Download.user.js +++ b/GithubEnhanced-High-Speed-Download.user.js @@ -3,7 +3,7 @@ // @name:en Github Enhancement - High Speed Download // @name:zh-CN Github 增强 - 高速下载 // @name:zh-TW Github 增強 - 高速下載 -// @version 1.8.3 +// @version 1.8.4 // @author X.I.U // @description 高速下载 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 (☁) @@ -28,20 +28,7 @@ (function() { 'use strict'; - var 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') { - backColor = '#272e37'; fontColor = '#768390'; - } else { - backColor = '#161a21'; fontColor = '#97a0aa'; - } - } else if (document.getElementsByTagName('html')[0].getAttribute('data-color-mode') === 'auto') { - if (window.getComputedStyle(document.body).backgroundColor === 'rgb(34, 39, 46)') { - backColor = '#272e37'; fontColor = '#768390'; - } else if (window.getComputedStyle(document.body).backgroundColor === 'rgb(13, 17, 23)') { - backColor = '#161a21'; fontColor = '#97a0aa'; - } - } + var backColor = '#ffffff', fontColor = '#888888', menu_raw_fast = GM_getValue('xiu2_menu_raw_fast'), menu_menu_raw_fast_ID, menu_feedBack_ID; const download_url = [ ['https://pd.zwc365.com/seturl/https://github.com', '美国 1'], ['https://gh.xiu.workers.dev/https://github.com', '美国 2'], @@ -52,7 +39,7 @@ ['https://download.fastgit.org', '日本'], ['https://ghproxy.com/https://github.com', '韩国'] //['https://ghproxy.fsou.cc/https://github.com', '香港'] - ], + ], clone_url = [ ['https://gitclone.com', '中国浙江'], ['https://github.com.cnpmjs.org', '新加坡'], @@ -79,10 +66,9 @@ '', '' ], - style = ['padding:0 6px;margin-right: -1px;border-radius: 2px;background-color: '+backColor+';border-color: rgba(27, 31, 35, 0.1);font-size: 11px;color: '+fontColor+';']; - var menu_raw_fast = GM_getValue('xiu2_menu_raw_fast'), menu_menu_raw_fast_ID, menu_feedBack_ID; - if (menu_raw_fast == null){menu_raw_fast = 1; GM_setValue('xiu2_menu_raw_fast', 1)}; + 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)}; registerMenuCommand(); // 注册脚本菜单 function registerMenuCommand() { @@ -117,6 +103,7 @@ return ['0️⃣','1️⃣','2️⃣','3️⃣','4️⃣','5️⃣','6️⃣','7️⃣','8️⃣','9️⃣','🔟'][num] } + colorMode(); addRelease(); // Release 加速 setTimeout(addDownloadZIP, 2000); // Download ZIP 加速 setTimeout(addGitClone, 2000); // Git Clone 加速 @@ -125,6 +112,7 @@ setTimeout(addRawDownLink, 2000); // 添加 Raw 下载链接(☁),延迟 2 秒执行,避免被 pjax 刷掉 document.addEventListener('pjax:success',function(){ // pjax 事件发生后 + colorMode(); addRelease(); // Release 加速 setTimeout(addDownloadZIP, 2000); // Download ZIP 加速 setTimeout(addGitClone, 2000); // Git Clone 加速 @@ -340,6 +328,32 @@ } + // 适配白天/夜间主题模式 + function colorMode() { + let style_Add; + 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') { + 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') { + backColor = '#272e37'; fontColor = '#768390'; + } else if (document.getElementsByTagName('html')[0].getAttribute('data-dark-theme').indexOf('light') == -1) { // 排除夜间模式是 light 的情况 + backColor = '#161a21'; fontColor = '#97a0aa'; + } + } + } + + document.lastElementChild.appendChild(style_Add).textContent = `.XIU2-RS a {--XIU2-back-Color: ${backColor}; --XIU2-font-Color: ${fontColor};}`; + } + + // 自定义 urlchange 事件(用来监听 URL 变化) function addUrlChangeEvent() { history.pushState = ( f => function pushState(){