Skip to content

Commit bd6a2af

Browse files
committed
优化 代码; 移除 旧版 Release 样式的支持 (Github 已完全更新)
1 parent bf556d7 commit bd6a2af

1 file changed

Lines changed: 34 additions & 104 deletions

File tree

GithubEnhanced-High-Speed-Download.user.js

Lines changed: 34 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name Github 增强 - 高速下载
3-
// @version 1.6.6
3+
// @version 1.6.7
44
// @author X.I.U
55
// @description 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁)
66
// @match *://github.com/*
@@ -21,34 +21,28 @@
2121

2222
(function() {
2323
'use strict';
24-
var backColor = '#ffffff';
25-
var fontColor = '#888888';
24+
var backColor = '#ffffff', fontColor = '#888888';
2625
if (document.getElementsByTagName('html')[0].getAttribute('data-color-mode') === 'dark') { // 黑暗模式判断
2726
if (document.getElementsByTagName('html')[0].getAttribute('data-dark-theme') === 'dark_dimmed') {
28-
backColor = '#272e37';
29-
fontColor = '#768390';
27+
backColor = '#272e37'; fontColor = '#768390';
3028
} else {
31-
backColor = '#161a21';
32-
fontColor = '#97a0aa';
29+
backColor = '#161a21'; fontColor = '#97a0aa';
3330
}
3431
} else if (document.getElementsByTagName('html')[0].getAttribute('data-color-mode') === 'auto') {
35-
//console.log(window.getComputedStyle(document.body).backgroundColor)
3632
if (window.getComputedStyle(document.body).backgroundColor === 'rgb(34, 39, 46)') {
37-
backColor = '#272e37';
38-
fontColor = '#768390';
33+
backColor = '#272e37'; fontColor = '#768390';
3934
} else if (window.getComputedStyle(document.body).backgroundColor === 'rgb(13, 17, 23)') {
40-
backColor = '#161a21';
41-
fontColor = '#97a0aa';
35+
backColor = '#161a21'; fontColor = '#97a0aa';
4236
}
4337
}
4438
const download_url = [
45-
['https://gh.api.99988866.xyz', '美国 1'],
46-
['https://github.91chifun.workers.dev', '美国 2'],
47-
['https://gh.xiu2.xyz', '美国 3'],
39+
['https://gh.api.99988866.xyz/https://github.com', '美国 1'],
40+
['https://github.91chifun.workers.dev/https://github.com', '美国 2'],
41+
['https://gh.xiu2.xyz/https://github.com', '美国 3'],
4842
['https://github.rc1844.workers.dev', '美国 4'],
49-
['https://pd.zwc365.com/seturl', '美国 5'],
43+
['https://pd.zwc365.com/seturl/https://github.com', '美国 5'],
5044
['https://download.fastgit.org', '日本'],
51-
['https://ghproxy.com', '韩国']
45+
['https://ghproxy.com/https://github.com/', '韩国']
5246
],
5347
clone_url = [
5448
['https://hub.fastgit.org', '中国香港'],
@@ -132,89 +126,28 @@
132126

133127
// Release
134128
function addRelease() {
135-
let html = document.getElementsByClassName('Box-footer');//if (html.length == 0) return
129+
let html = document.getElementsByClassName('Box-footer'); if (html.length == 0) return
136130
let divDisplay = '';
137-
if (html.length > 0) {
138-
if (document.documentElement.clientWidth > 1000) {divDisplay = 'float: right;margin-top: -3px;margin-left: 8px;';}; // 调整小屏幕下样式
139-
Array.from(html).forEach(function (current) {
140-
current.querySelectorAll('li.Box-row > a').forEach(function (_this) {
141-
let href = _this.href.split(location.host),
142-
url = [],
143-
_html = `<div style="${divDisplay}">`;
144-
145-
for (let i=0;i<download_url.length;i++){
146-
console.log(download_url[i][0])
147-
if (download_url[i][0] === 'https://download.fastgit.org' || download_url[i][0] === 'https://github.rc1844.workers.dev') {
148-
url[i] = download_url[i][0] + href[1]
149-
} else {
150-
url[i] = download_url[i][0] + '/' + _this.href
151-
}
152-
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
153-
}
154-
155-
for (let i=0;i<url.length;i++) {
156-
_html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
157-
}
158-
_html += `</div>`
159-
_this.insertAdjacentHTML('afterend', _html);
160-
});
131+
if (document.documentElement.clientWidth > 1000) {divDisplay = 'float: right;margin-top: -3px;margin-left: 8px;';}; // 调整小屏幕时的样式
132+
Array.from(html).forEach(function (current) {
133+
current.querySelectorAll('li.Box-row > a').forEach(function (_this) {
134+
let href = _this.href.split(location.host),
135+
url = [],
136+
_html = `<div style="${divDisplay}">`;
137+
// 循环组合 URL 链接
138+
for (let i=0;i<download_url.length;i++){
139+
url[i] = download_url[i][0] + href[1]
140+
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
141+
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')
142+
}
143+
// 循环生成 HTML 标签
144+
for (let i=0;i<url.length;i++) {
145+
_html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
146+
}
147+
_html += `</div>`
148+
_this.insertAdjacentHTML('afterend', _html);
161149
});
162-
} else if (document.getElementsByClassName('Box Box--condensed').length > 0) {
163-
html = document.getElementsByClassName('Box Box--condensed')
164-
if (document.documentElement.clientWidth > 1000) {divDisplay = 'display: flex;';} else {divDisplay = 'display: block;';}
165-
Array.from(html).forEach(function (current) {
166-
current.querySelectorAll('.d-flex.Box-body > a').forEach(function (_this) {
167-
let href = _this.href.split(location.host),
168-
url = [],
169-
_html = `<div style="${divDisplay}justify-content: flex-end;">`;
170-
171-
for (let i=0;i<download_url.length;i++){
172-
console.log(download_url[i][0])
173-
if (download_url[i][0] === 'https://download.fastgit.org' || download_url[i][0] === 'https://github.rc1844.workers.dev') {
174-
url[i] = download_url[i][0] + href[1]
175-
} else {
176-
url[i] = download_url[i][0] + '/' + _this.href
177-
}
178-
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
179-
}
180-
181-
for (let i=0;i<url.length;i++) {
182-
_html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
183-
}
184-
_html += `</div>`
185-
_this.nextElementSibling.insertAdjacentHTML('afterend', _html);
186-
});
187-
// 修改[文件大小]元素样式
188-
document.querySelectorAll('.Box.Box--condensed small').forEach(el=>{el.style.cssText='display: flex; justify-content: flex-end; flex-grow: 1; margin-right: 8px;'});
189-
190-
191-
// Source Code
192-
current.querySelectorAll('.d-block.Box-body > a').forEach(function (_this) {
193-
let href = _this.href.split(location.host),
194-
url = [],
195-
_html = `<div style="${divDisplay}justify-content: flex-end;flex-grow: 1;">`;
196-
197-
for (let i=0;i<download_url.length;i++){
198-
if (download_url[i][0] === 'https://download.fastgit.org') {
199-
url[i] = download_url[i][0] + href[1]
200-
} else {
201-
url[i] = download_url[i][0] + '/' + _this.href
202-
}
203-
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
204-
}
205-
206-
for (let i=0;i<url.length;i++) {
207-
_html += `<a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a>`
208-
}
209-
_html += `</div>`
210-
_this.insertAdjacentHTML('afterend', _html);
211-
});
212-
});
213-
// 修改 Source code 样式,使其和加速按钮并列一排
214-
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'});
215-
} else {
216-
return
217-
}
150+
});
218151
}
219152

220153

@@ -227,12 +160,9 @@
227160
_html = ``;
228161

229162
for (let i=0;i<download_url.length;i++){
230-
if (download_url[i][0] === 'https://download.fastgit.org') {
231-
url[i] = download_url[i][0] + href.split(location.host)[1]
232-
} else {
233-
url[i] = download_url[i][0] + '/' + href
234-
}
163+
url[i] = download_url[i][0] + href.split(location.host)[1]
235164
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
165+
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')
236166
}
237167

238168
for (let i=0;i<url.length;i++) {
@@ -276,7 +206,7 @@
276206
if (href_split[0] != 'git@github.com') return
277207

278208
for (let i=0;i<clone_ssh_url.length;i++){
279-
url[i] = clone_ssh_url[i][0] + ':' + href_split[1]
209+
url[i] = clone_ssh_url[i][0] + ':' + href_split[1]
280210
}
281211

282212
for (let i=0;i<url.length;i++) {

0 commit comments

Comments
 (0)