Skip to content

Commit f203a1a

Browse files
committed
修复 在 fastgit 镜像站时脚本加速源 URL 有误的问题
1 parent a878f90 commit f203a1a

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

GithubEnhanced-High-Speed-Download.user.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name Github 增强 - 高速下载
3-
// @version 1.5.4
3+
// @version 1.5.5
44
// @author X.I.U
55
// @description 高速下载 Git Clone/SSH、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁)
66
// @match *://github.com/*
@@ -143,7 +143,7 @@
143143
}
144144
Array.from(html).forEach(function (current) {
145145
current.querySelectorAll('.d-flex.Box-body > a').forEach(function (_this) {
146-
let href = _this.href.split('github.com'),
146+
let href = _this.href.split(location.host),
147147
url = [],
148148
_html = `<div style="${divDisplay}justify-content: flex-end;">`;
149149

@@ -153,6 +153,7 @@
153153
} else {
154154
url[i] = download_url[i][0] + '/' + _this.href
155155
}
156+
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
156157
}
157158

158159
for (let i=0;i<url.length;i++) {
@@ -167,7 +168,7 @@
167168

168169
// Source Code
169170
current.querySelectorAll('.d-block.Box-body > a').forEach(function (_this) {
170-
let href = _this.href.split('github.com'),
171+
let href = _this.href.split(location.host),
171172
url = [],
172173
_html = `<div style="${divDisplay}justify-content: flex-end;flex-grow: 1;">`;
173174

@@ -177,6 +178,7 @@
177178
} else {
178179
url[i] = download_url[i][0] + '/' + _this.href
179180
}
181+
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
180182
}
181183

182184
for (let i=0;i<url.length;i++) {
@@ -200,10 +202,11 @@
200202

201203
for (let i=0;i<download_url.length;i++){
202204
if (download_url[i][0] === 'https://download.fastgit.org') {
203-
url[i] = download_url[i][0] + href.split('github.com')[1]
205+
url[i] = download_url[i][0] + href.split(location.host)[1]
204206
} else {
205207
url[i] = download_url[i][0] + '/' + href
206208
}
209+
if (location.host === 'hub.fastgit.org') url[i] = url[i].replace('hub.fastgit.org','github.com')
207210
}
208211

209212
for (let i=0;i<url.length;i++) {
@@ -216,7 +219,7 @@
216219
// Git Clone
217220
function addGitClone() {
218221
let html = document.querySelector('[role="tabpanel"]:nth-child(2) div.input-group');if (!html) return
219-
let href_split = html.getElementsByTagName('input')[0].getAttribute('value').split('github.com'),
222+
let href_split = html.getElementsByTagName('input')[0].getAttribute('value').split(location.host),
220223
url = [],
221224
_html = ``;
222225

@@ -258,7 +261,7 @@
258261
// Raw
259262
function addRawFile() {
260263
let html = document.getElementById('raw-url');if (!html) return
261-
let href = location.href.replace('https://github.com',''),
264+
let href = location.href.replace(`https://${location.host}`,''),
262265
href2 = href.replace('/blob/','/'),
263266
url = [
264267
raw_url[1][0] + "/gh" + href.replace('/blob/','@'),
@@ -304,7 +307,7 @@
304307
cntElm_a = trElm.querySelector('.css-truncate.css-truncate-target.d-block.width-fit a'),
305308
cntElm_svg = trElm.querySelector('.mr-3.flex-shrink-0 svg.octicon.octicon-file.color-icon-tertiary'),
306309
Name = cntElm_a.innerText,
307-
href = cntElm_a.attributes.href.nodeValue.replace('https://github.com','');
310+
href = cntElm_a.attributes.href.nodeValue.replace(`https://${location.host}`,'');
308311
let href2 = href.replace('/blob/','/'), url, url_name, url_tip = '';
309312
switch(menu_raw_fast) {
310313
case 1:

0 commit comments

Comments
 (0)