优化 代码; 移除 旧版 Release 样式的支持 (Github 已完全更新)

This commit is contained in:
xiu2
2021-11-18 18:12:51 +08:00
parent bf556d763a
commit bd6a2af7f2
+34 -104
View File
@@ -1,6 +1,6 @@
// ==UserScript==
// @name Github 增强 - 高速下载
// @version 1.6.6
// @version 1.6.7
// @author X.I.U
// @description 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁)
// @match *://github.com/*
@@ -21,34 +21,28 @@
(function() {
'use strict';
var backColor = '#ffffff';
var fontColor = '#888888';
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';
backColor = '#272e37'; fontColor = '#768390';
} else {
backColor = '#161a21';
fontColor = '#97a0aa';
backColor = '#161a21'; fontColor = '#97a0aa';
}
} else if (document.getElementsByTagName('html')[0].getAttribute('data-color-mode') === 'auto') {
//console.log(window.getComputedStyle(document.body).backgroundColor)
if (window.getComputedStyle(document.body).backgroundColor === 'rgb(34, 39, 46)') {
backColor = '#272e37';
fontColor = '#768390';
backColor = '#272e37'; fontColor = '#768390';
} else if (window.getComputedStyle(document.body).backgroundColor === 'rgb(13, 17, 23)') {
backColor = '#161a21';
fontColor = '#97a0aa';
backColor = '#161a21'; fontColor = '#97a0aa';
}
}
const download_url = [
['https://gh.api.99988866.xyz', '美国 1'],
['https://github.91chifun.workers.dev', '美国 2'],
['https://gh.xiu2.xyz', '美国 3'],
['https://gh.api.99988866.xyz/https://github.com', '美国 1'],
['https://github.91chifun.workers.dev/https://github.com', '美国 2'],
['https://gh.xiu2.xyz/https://github.com', '美国 3'],
['https://github.rc1844.workers.dev', '美国 4'],
['https://pd.zwc365.com/seturl', '美国 5'],
['https://pd.zwc365.com/seturl/https://github.com', '美国 5'],
['https://download.fastgit.org', '日本'],
['https://ghproxy.com', '韩国']
['https://ghproxy.com/https://github.com/', '韩国']
],
clone_url = [
['https://hub.fastgit.org', '中国香港'],
@@ -132,89 +126,28 @@
// Release
function addRelease() {
let html = document.getElementsByClassName('Box-footer');//if (html.length == 0) return
let html = document.getElementsByClassName('Box-footer'); if (html.length == 0) return
let divDisplay = '';
if (html.length > 0) {
if (document.documentElement.clientWidth > 1000) {divDisplay = 'float: right;margin-top: -3px;margin-left: 8px;';}; // 调整小屏幕下样式
Array.from(html).forEach(function (current) {
current.querySelectorAll('li.Box-row > a').forEach(function (_this) {
let href = _this.href.split(location.host),
url = [],
_html = `<div style="${divDisplay}">`;
for (let i=0;i<download_url.length;i++){
console.log(download_url[i][0])
if (download_url[i][0] === 'https://download.fastgit.org' || download_url[i][0] === 'https://github.rc1844.workers.dev') {
url[i] = download_url[i][0] + href[1]
} else {
url[i] = download_url[i][0] + '/' + _this.href
}
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
}
for (let i=0;i<url.length;i++) {
_html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
}
_html += `</div>`
_this.insertAdjacentHTML('afterend', _html);
});
if (document.documentElement.clientWidth > 1000) {divDisplay = 'float: right;margin-top: -3px;margin-left: 8px;';}; // 调整小屏幕时的样式
Array.from(html).forEach(function (current) {
current.querySelectorAll('li.Box-row > a').forEach(function (_this) {
let href = _this.href.split(location.host),
url = [],
_html = `<div style="${divDisplay}">`;
// 循环组合 URL 链接
for (let i=0;i<download_url.length;i++){
url[i] = download_url[i][0] + href[1]
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
if (download_url[i][0] === 'https://download.fastgit.org' && url[i].indexOf('/archive/') > -1) url[i] = url[i].replace('https://download.fastgit.org','https://archive.fastgit.org')
}
// 循环生成 HTML 标签
for (let i=0;i<url.length;i++) {
_html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
}
_html += `</div>`
_this.insertAdjacentHTML('afterend', _html);
});
} else if (document.getElementsByClassName('Box Box--condensed').length > 0) {
html = document.getElementsByClassName('Box Box--condensed')
if (document.documentElement.clientWidth > 1000) {divDisplay = 'display: flex;';} else {divDisplay = 'display: block;';}
Array.from(html).forEach(function (current) {
current.querySelectorAll('.d-flex.Box-body > a').forEach(function (_this) {
let href = _this.href.split(location.host),
url = [],
_html = `<div style="${divDisplay}justify-content: flex-end;">`;
for (let i=0;i<download_url.length;i++){
console.log(download_url[i][0])
if (download_url[i][0] === 'https://download.fastgit.org' || download_url[i][0] === 'https://github.rc1844.workers.dev') {
url[i] = download_url[i][0] + href[1]
} else {
url[i] = download_url[i][0] + '/' + _this.href
}
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
}
for (let i=0;i<url.length;i++) {
_html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
}
_html += `</div>`
_this.nextElementSibling.insertAdjacentHTML('afterend', _html);
});
// 修改[文件大小]元素样式
document.querySelectorAll('.Box.Box--condensed small').forEach(el=>{el.style.cssText='display: flex; justify-content: flex-end; flex-grow: 1; margin-right: 8px;'});
// Source Code
current.querySelectorAll('.d-block.Box-body > a').forEach(function (_this) {
let href = _this.href.split(location.host),
url = [],
_html = `<div style="${divDisplay}justify-content: flex-end;flex-grow: 1;">`;
for (let i=0;i<download_url.length;i++){
if (download_url[i][0] === 'https://download.fastgit.org') {
url[i] = download_url[i][0] + href[1]
} else {
url[i] = download_url[i][0] + '/' + _this.href
}
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
}
for (let i=0;i<url.length;i++) {
_html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
}
_html += `</div>`
_this.insertAdjacentHTML('afterend', _html);
});
});
// 修改 Source code 样式,使其和加速按钮并列一排
document.querySelectorAll('div.d-block.py-1.py-md-2.Box-body.px-2').forEach(el=>{el.className='d-flex py-1 py-md-2 Box-body px-2'});
} else {
return
}
});
}
@@ -227,12 +160,9 @@
_html = ``;
for (let i=0;i<download_url.length;i++){
if (download_url[i][0] === 'https://download.fastgit.org') {
url[i] = download_url[i][0] + href.split(location.host)[1]
} else {
url[i] = download_url[i][0] + '/' + href
}
url[i] = download_url[i][0] + href.split(location.host)[1]
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
if (download_url[i][0] === 'https://download.fastgit.org' && url[i].indexOf('/archive/') > -1) url[i] = url[i].replace('https://download.fastgit.org','https://archive.fastgit.org')
}
for (let i=0;i<url.length;i++) {
@@ -276,7 +206,7 @@
if (href_split[0] != 'git@github.com') return
for (let i=0;i<clone_ssh_url.length;i++){
url[i] = clone_ssh_url[i][0] + ':' + href_split[1]
url[i] = clone_ssh_url[i][0] + ':' + href_split[1]
}
for (let i=0;i<url.length;i++) {