小调整

scripts
王良 2024-04-27 23:50:54 +08:00
parent d9454c4f86
commit eb6ada22d5
1 changed files with 20 additions and 23 deletions

View File

@ -4,8 +4,8 @@
*
* @name Github 增强 - 高速下载Github油猴脚本
* @name:en Github Enhancement - High Speed DownloadGithub Greasemonkey Script
* @version 2.5.20_3
* @since 2024-04-24 17:38
* @version 2.5.21_1
* @since 2024-04-27 23:48
* @author X.I.U
* @description 高速下载 Git Clone/SSHReleaseRawCode(ZIP) 等文件 (公益加速)项目列表单文件快捷下载 ()添加 git clone 命令
* @description:en High-speed download of Git Clone/SSH, Release, Raw, Code(ZIP) and other files (Based on public welfare), project list file quick download ()
@ -15,7 +15,7 @@
* @homepageURL https://github.com/XIU2/UserScript
* @sourceURL https://github.com/XIU2/UserScript/blob/master/GithubEnhanced-High-Speed-Download.user.js
*/
var ds_github_monkey_version = "2.5.20_3";
const ds_github_monkey_version = "2.5.21_1";
document.addEventListener("DOMContentLoaded", () => {
const DS_init = (window.__ds_global__ || {})['DS_init']
if (typeof DS_init === 'function') {
@ -143,9 +143,9 @@ document.addEventListener("DOMContentLoaded", () => {
'<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>'
], 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_rawFast == null){menu_rawFast = 1; GM_setValue('xiu2_menu_raw_fast', 1)}
if (GM_getValue('menu_rawDownLink') == null){GM_setValue('menu_rawDownLink', true)}
if (GM_getValue('menu_gitClone') == null){GM_setValue('menu_gitClone', true)}
if (menu_rawFast == null){menu_rawFast = 1; GM_setValue('xiu2_menu_raw_fast', 1)};
if (GM_getValue('menu_rawDownLink') == null){GM_setValue('menu_rawDownLink', true)};
if (GM_getValue('menu_gitClone') == null){GM_setValue('menu_gitClone', true)};
registerMenuCommand();
// 注册脚本菜单
function registerMenuCommand() {
@ -153,10 +153,10 @@ document.addEventListener("DOMContentLoaded", () => {
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');}
// 避免在减少 raw 数组后,用户储存的数据大于数组而报错
if (menu_rawFast > raw_url.length - 1) menu_rawFast = 0
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();}, {title: "点击开关「项目列表单文件快捷下载 (☁)」功能"});
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();}, {title: "点击开关「项目列表单文件快捷下载 (☁)」功能"});
if (GM_getValue('menu_rawDownLink')) menu_rawFast_ID = GM_registerMenuCommand(`&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${['0⃣','1⃣','2⃣','3⃣','4⃣','5⃣','6⃣','7⃣','8⃣','9⃣','🔟'][menu_rawFast]} [ ${raw_url[menu_rawFast][1]} ] 加速源 (☁) - 点击切换`, menu_toggle_raw_fast, {title: "点击切换「项目列表单文件快捷下载 (☁)」功能的加速源"});
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 命令」功能`, timeout: 3500});} else {GM_setValue('menu_gitClone', true); GM_notification({text: `已开启「添加 git clone 命令」功能`, timeout: 3500});}registerMenuCommand();}, {title: "点击开关「添加 git clone 命令」功能"});
menu_feedBack_ID = GM_registerMenuCommand('💬 反馈问题 & 功能建议', function () {GM_openInTab('https://github.com/XIU2/UserScript/issues/new', {active: true,insert: true,setParent: true});GM_openInTab('https://greasyfork.org/zh-CN/scripts/412245/feedback', {active: true,insert: true,setParent: true});}, {title: "点击前往反馈问题或提出建议"});
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 命令」功能`, timeout: 3500});} else {GM_setValue('menu_gitClone', true); GM_notification({text: `已开启「添加 git clone 命令」功能`, timeout: 3500});}registerMenuCommand();}, {title: "点击开关「添加 git clone 命令」功能"});
menu_feedBack_ID = GM_registerMenuCommand('💬 反馈问题 & 功能建议', function () {GM_openInTab('https://github.com/XIU2/UserScript', {active: true,insert: true,setParent: true});GM_openInTab('https://greasyfork.org/zh-CN/scripts/412245/feedback', {active: true,insert: true,setParent: true});}, {title: "点击前往反馈问题或提出建议"});
}
// 切换加速源
@ -168,7 +168,7 @@ document.addEventListener("DOMContentLoaded", () => {
addRawDownLink(); // 添加新加速源
GM_notification({text: "已切换加速源为:" + raw_url[menu_rawFast][1], timeout: 3000}); // 提示消息
registerMenuCommand(); // 重新注册脚本菜单
}
};
colorMode(); // 适配白天/夜间主题模式
setTimeout(addRawFile, 1000); // Raw 加速
@ -234,7 +234,7 @@ document.addEventListener("DOMContentLoaded", () => {
let html = document.querySelectorAll('.Box-footer');
if (html.length === 0 || location.pathname.indexOf('/releases') === -1) return;
let divDisplay = 'margin-left: -90px;', new_download_url = get_New_download_url();
if (document.documentElement.clientWidth > 755) {divDisplay = 'margin-top: -3px;margin-left: 8px;display: inherit;';} // 调整小屏幕时的样式
if (document.documentElement.clientWidth > 755) {divDisplay = 'margin-top: -3px;margin-left: 8px;display: inherit;';}; // 调整小屏幕时的样式
for (const current of html) {
if (current.querySelector('.XIU2-RS')) continue
current.querySelectorAll('li.Box-row a').forEach(function (_this) {
@ -292,13 +292,12 @@ document.addEventListener("DOMContentLoaded", () => {
// Git Clone
function addGitClone(target) {
let html = target.querySelector('input[value^="https:"]');
if (!html) return;
let html = target.querySelector('input[value^="https:"]');if (!html) return
if (!html.nextElementSibling) return false;
let href_split = html.value.replace(/https:\/\/[^/]+/, ''),
let href_split = html.value.split(location.host)[1],
html_parent = '<div style="margin-top: 4px;" class="XIU2-GC ' + html.parentElement.className + '">',
url = '', _html = '', _gitClone = '';
html.nextElementSibling.hidden = true; // 隐藏右侧复制按钮
html.nextElementSibling.hidden = true; // 隐藏右侧复制按钮(考虑到能直接点击复制,就不再重复实现复制按钮事件了)
if (GM_getValue('menu_gitClone')) {_gitClone='git clone '; html.value = _gitClone + html.value; html.setAttribute('value', html.value);}
// 克隆原 Git Clone 元素
let html_clone = html.cloneNode(true);
@ -308,7 +307,7 @@ document.addEventListener("DOMContentLoaded", () => {
} else {
url = clone_url[i][0] + href_split
}
html_clone.title = `${url}\n加速源:${clone_url[i][1]} (点击可直接复制)\n${clone_url[i][2].replaceAll('&#10;','\n')}`
html_clone.title = `${url}\n\n${clone_url[i][2].replaceAll('&#10;','\n')}\n\n提示:点击文字可直接复制`
html_clone.setAttribute('value', _gitClone + url)
_html += html_parent + html_clone.outerHTML + '</div>'
}
@ -318,19 +317,18 @@ document.addEventListener("DOMContentLoaded", () => {
// Git Clone SSH
function addGitCloneSSH(target) {
let html = target.querySelector('input[value^="git@"]');
if (!html) return;
let html = target.querySelector('input[value^="git@"]');if (!html) return
if (!html.nextElementSibling) return false;
let href_split = html.value.split(':')[1],
html_parent = '<div style="margin-top: 4px;" class="XIU2-GCS ' + html.parentElement.className + '">',
url = '', _html = '', _gitClone = '';
html.nextElementSibling.hidden = true; // 隐藏右侧复制按钮
html.nextElementSibling.hidden = true; // 隐藏右侧复制按钮(考虑到能直接点击复制,就不再重复实现复制按钮事件了)
if (GM_getValue('menu_gitClone')) {_gitClone='git clone '; html.value = _gitClone + html.value; html.setAttribute('value', html.value);}
// 克隆原 Git Clone SSH 元素
let html_clone = html.cloneNode(true);
for (let i=0;i<clone_ssh_url.length;i++) {
url = clone_ssh_url[i][0] + href_split
html_clone.title = `${url}\n加速源:${clone_ssh_url[i][1]} (点击可直接复制)\n${clone_ssh_url[i][2].replaceAll('&#10;','\n')}`
html_clone.title = `${url}\n\n${clone_ssh_url[i][2].replaceAll('&#10;','\n')}\n\n提示:点击文字可直接复制`
html_clone.setAttribute('value', _gitClone + url)
_html += html_parent + html_clone.outerHTML + '</div>'
}
@ -340,8 +338,7 @@ document.addEventListener("DOMContentLoaded", () => {
// Raw
function addRawFile() {
let html = document.querySelector('a[data-testid="raw-button"]');
if (!html) return;
let html = document.querySelector('a[data-testid="raw-button"]');if (!html) return
let href = location.href.replace(`https://${location.host}`,''),
href2 = href.replace('/blob/','/'),
url = '', _html = '';
@ -464,7 +461,7 @@ document.addEventListener("DOMContentLoaded", () => {
if (window.matchMedia && 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.lastElementChild.dataset.darkTheme.indexOf('light') === -1) { // 排除夜间模式是 light 的情况
} else if (document.lastElementChild.dataset.darkTheme.indexOf('light') == -1) { // 排除夜间模式是 light 的情况
backColor = '#161a21'; fontColor = '#97a0aa';
}
}