Skip to content

Commit a9bdb58

Browse files
committed
新增 Git Clone 加速源提示(鼠标指向时显示);优化 脚本代码
1 parent e299e13 commit a9bdb58

1 file changed

Lines changed: 51 additions & 60 deletions

File tree

GithubEnhanced-High-Speed-Download.user.js

Lines changed: 51 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ==UserScript==
22
// @name Github 增强 - 高速下载
3-
// @version 1.3.4
3+
// @version 1.3.5
44
// @author X.I.U
5-
// @description 高速下载 Clone、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁)
5+
// @description 高速下载 Git Clone、Release、Raw、Code(ZIP) 等文件、项目列表单文件快捷下载 (☁)
66
// @match *://github.com/*
77
// @icon https://github.com/favicon.ico
88
// @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
@@ -33,15 +33,15 @@
3333
['https://pd.zwc365.com/seturl','中国香港']
3434
],
3535
clone_url = [
36-
'https://hub.fastgit.org',
37-
'https://gitclone.com',
38-
'https://ghp.lvmhsh.cn.cnpmjs.org'
36+
['https://hub.fastgit.org','中国香港'],
37+
['https://gitclone.com','中国浙江杭州'],
38+
['https://ghp.lvmhsh.cn.cnpmjs.org','新加坡']
3939
],
4040
raw_url = [
4141
['https://raw.githubusercontent.com','Github 原生',''],
4242
['https://raw.sevencdn.com','中国国内 01',''],
43-
['https://cdn.jsdelivr.net','中国国内 02','注意:该加速源存在缓存机制(24小时),所以文件可能不是最新。
注意:当前分支所有文件总文件大小超过 50MB 时,该加速源不可用。
注意:当前分支名为版本号格式时(如 v1.2.3),该高速下载链接因格式限制不可用。

'],
44-
['https://raw.fastgit.org','中国香港','注意:单个文件太大时可能会提示超时(实时获取中),请重试。

'],
43+
['https://cdn.jsdelivr.net','中国国内 02','注意:该加速源存在缓存机制(24小时),所以文件可能不是最新。
注意:当前分支所有文件总文件大小超过 50MB 时,该加速源不可用。
注意:当前分支名为版本号格式时(如 v1.2.3),该高速下载链接因格式限制不可用。'],
44+
['https://raw.fastgit.org','中国香港','注意:单个文件太大时可能会提示超时(实时获取中),请重试。'],
4545
['https://ghproxy.com','韩国首尔','']
4646
],
4747
svg = [
@@ -50,7 +50,6 @@
5050
'<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>'
5151
],
5252
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+';'],
53-
5453
menu_raw_fast = GM_getValue('xiu2_menu_raw_fast'),
5554
menu_menu_raw_fast_ID, menu_feedBack_ID;
5655
if (menu_raw_fast == null || menu_raw_fast == '中国国内'){menu_raw_fast = 1; GM_setValue('xiu2_menu_raw_fast', 1)}; // 调整上个版本的设置存储变量内容
@@ -103,7 +102,7 @@
103102
function addRelease(){
104103
$(".Box.Box--condensed").each(function () {
105104
$(this).find(".d-flex.Box-body>a").each(function () {
106-
var href = $(this).attr("href"),
105+
let href = $(this).attr("href"),
107106
url = [
108107
download_url[0][0] + '/https://github.com' + href,
109108
download_url[1][0] + '/https://github.com' + href,
@@ -112,14 +111,12 @@
112111
download_url[4][0] + '/https://github.com' + href,
113112
download_url[5][0] + '/https://github.com' + href
114113
],
115-
html = `<div style="display: flex;justify-content: flex-end;">
116-
<div><a style="${style[0]}" class="btn" href="${url[0]}" rel="noreferrer noopener nofollow">${download_url[0][1]}</a></div>
117-
<div><a style="${style[0]}" class="btn" href="${url[1]}" rel="noreferrer noopener nofollow">${download_url[1][1]}</a></div>
118-
<div><a style="${style[0]}" class="btn" href="${url[2]}" rel="noreferrer noopener nofollow">${download_url[2][1]}</a></div>
119-
<div><a style="${style[0]}" class="btn" href="${url[3]}" rel="noreferrer noopener nofollow">${download_url[3][1]}</a></div>
120-
<div><a style="${style[0]}" class="btn" href="${url[4]}" rel="noreferrer noopener nofollow">${download_url[4][1]}</a></div>
121-
<div><a style="${style[0]}" class="btn" href="${url[5]}" rel="noreferrer noopener nofollow">${download_url[5][1]}</a></div>
122-
</div>`;
114+
html = `<div style="display: flex;justify-content: flex-end;">`;
115+
for (let i=0;i<url.length;i++)
116+
{
117+
html = html + `<div><a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a></div>`
118+
}
119+
html = html + `</div>`
123120
$(this).next().after(html);
124121
});
125122
// 修改[文件大小]元素样式
@@ -128,7 +125,7 @@
128125

129126
// Source Code
130127
$(this).find(".d-block.Box-body>a").each(function () {
131-
var href = $(this).attr("href"),
128+
let href = $(this).attr("href"),
132129
url = [
133130
download_url[0][0] + '/https://github.com' + href,
134131
download_url[1][0] + '/https://github.com' + href,
@@ -137,14 +134,12 @@
137134
download_url[4][0] + '/https://github.com' + href,
138135
download_url[5][0] + '/https://github.com' + href
139136
],
140-
html = `<div style="display: flex;justify-content: flex-end;flex-grow: 1;">
141-
<div><a style="${style[0]}" class="btn" href="${url[0]}" rel="noreferrer noopener nofollow">${download_url[0][1]}</a></div>
142-
<div><a style="${style[0]}" class="btn" href="${url[1]}" rel="noreferrer noopener nofollow">${download_url[1][1]}</a></div>
143-
<div><a style="${style[0]}" class="btn" href="${url[2]}" rel="noreferrer noopener nofollow">${download_url[2][1]}</a></div>
144-
<div><a style="${style[0]}" class="btn" href="${url[3]}" rel="noreferrer noopener nofollow">${download_url[3][1]}</a></div>
145-
<div><a style="${style[0]}" class="btn" href="${url[4]}" rel="noreferrer noopener nofollow">${download_url[4][1]}</a></div>
146-
<div><a style="${style[0]}" class="btn" href="${url[5]}" rel="noreferrer noopener nofollow">${download_url[5][1]}</a></div>
147-
</div>`;
137+
html = `<div style="display: flex;justify-content: flex-end;flex-grow: 1;">`;
138+
for (let i=0;i<url.length;i++)
139+
{
140+
html = html + `<div><a style="${style[0]}" class="btn" href="${url[i]}" rel="noreferrer noopener nofollow">${download_url[i][1]}</a></div>`
141+
}
142+
html = html + `</div>`
148143
$(this).after(html);
149144
});
150145
});
@@ -156,7 +151,7 @@
156151
// Download ZIP
157152
function addDownloadZIP(){
158153
$(".dropdown-menu.dropdown-menu-sw.p-0 ul li:last-child").each(function () {
159-
var href = $(this).children("a").attr("href"),
154+
let href = $(this).children("a").attr("href"),
160155
url = [
161156
download_url[0][0] + "/https://github.com" + href,
162157
download_url[1][0] + "/https://github.com" + href,
@@ -165,14 +160,11 @@
165160
download_url[4][0] + "/https://github.com" + href,
166161
download_url[5][0] + '/https://github.com' + href
167162
],
168-
html = `
169-
<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[0]}">${svg[0]}Download ZIP ${download_url[0][1]}</a></li>
170-
<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[1]}">${svg[0]}Download ZIP ${download_url[1][1]}</a></li>
171-
<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[2]}">${svg[0]}Download ZIP ${download_url[2][1]}</a></li>
172-
<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[3]}">${svg[0]}Download ZIP ${download_url[3][1]}</a></li>
173-
<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[4]}">${svg[0]}Download ZIP ${download_url[4][1]}</a></li>
174-
<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[5]}">${svg[0]}Download ZIP ${download_url[5][1]}</a></li>
175-
`;
163+
html = ``;
164+
for (let i=0;i<url.length;i++)
165+
{
166+
html = html + `<li class="Box-row Box-row--hover-gray p-0"><a class="d-flex flex-items-center text-gray-dark text-bold no-underline p-3" rel="noreferrer noopener nofollow" href="${url[i]}">${svg[0]}Download ZIP ${download_url[i][1]}</a></li>`
167+
}
176168
$(this).after(html);
177169
});
178170
}
@@ -181,17 +173,17 @@
181173
// Git Clone
182174
function addGitClone(){
183175
$("[role='tabpanel'] div.input-group").first().each(function () {
184-
var href_split = location.href.split("/"),
176+
let href_split = location.href.split("/"),
185177
url = [
186-
clone_url[0] + "/" + href_split[3] + "/" + href_split[4] + ".git",
187-
clone_url[1] + "/github.com/" + href_split[3] + "/" + href_split[4] + ".git",
188-
clone_url[2] + "/" + href_split[3] + "/" + href_split[4] + ".git"
178+
clone_url[0][0] + "/" + href_split[3] + "/" + href_split[4] + ".git",
179+
clone_url[1][0] + "/github.com/" + href_split[3] + "/" + href_split[4] + ".git",
180+
clone_url[2][0] + "/" + href_split[3] + "/" + href_split[4] + ".git"
189181
],
190-
html = `
191-
<div class="input-group" style="margin-top: 4px;"><input value="${url[0]}" aria-label="${url[0]}" type="text" class="form-control input-monospace input-sm bg-gray-light" data-autoselect="" readonly=""><div class="input-group-button"><clipboard-copy value="${url[0]}" aria-label="Copy to clipboard" class="btn btn-sm" tabindex="0" role="button">${svg[1]}</clipboard-copy></div></div>
192-
<div class="input-group" style="margin-top: 4px;"><input value="${url[1]}" aria-label="${url[1]}" type="text" class="form-control input-monospace input-sm bg-gray-light" data-autoselect="" readonly=""><div class="input-group-button"><clipboard-copy value="${url[1]}" aria-label="Copy to clipboard" class="btn btn-sm" tabindex="0" role="button">${svg[1]}</clipboard-copy></div></div>
193-
<div class="input-group" style="margin-top: 4px;"><input value="${url[2]}" aria-label="${url[2]}" type="text" class="form-control input-monospace input-sm bg-gray-light" data-autoselect="" readonly=""><div class="input-group-button"><clipboard-copy value="${url[2]}" aria-label="Copy to clipboard" class="btn btn-sm" tabindex="0" role="button">${svg[1]}</clipboard-copy></div></div>
194-
`;
182+
html = ``;
183+
for (let i=0;i<url.length;i++)
184+
{
185+
html = html + `<div class="input-group" style="margin-top: 4px;" title="加速源:${clone_url[i][1]} (点击可直接复制)"><input value="${url[i]}" aria-label="${url[i]}" type="text" class="form-control input-monospace input-sm bg-gray-light" data-autoselect="" readonly=""><div class="input-group-button"><clipboard-copy value="${url[i]}" aria-label="Copy to clipboard" class="btn btn-sm" tabindex="0" role="button">${svg[1]}</clipboard-copy></div></div>`
186+
}
195187
$(this).after(html);
196188
});
197189
}
@@ -200,20 +192,19 @@
200192
// Raw
201193
function addRawFile(){
202194
$("#raw-url").each(function () {
203-
var href = location.href.replace('https://github.com',''),
195+
let href = location.href.replace('https://github.com',''),
204196
href2 = href.replace('/blob/','/'),
205197
url = [
206198
raw_url[1][0] + href2,
207199
raw_url[2][0] + "/gh" + href.replace('/blob/','@'),
208200
raw_url[3][0] + href2,
209201
raw_url[4][0] + "/" + raw_url[0][0] + href2
210202
],
211-
html = `
212-
<a href="${url[0]}" title="${raw_url[1][2]}" role="button" rel="noreferrer noopener nofollow" class="btn btn-sm BtnGroup-item">${raw_url[1][1]}</a>
213-
<a href="${url[1]}" title="${raw_url[2][2]}" role="button" rel="noreferrer noopener nofollow" class="btn btn-sm BtnGroup-item">${raw_url[2][1]}</a>
214-
<a href="${url[2]}" title="${raw_url[3][2]}" role="button" rel="noreferrer noopener nofollow" class="btn btn-sm BtnGroup-item">${raw_url[3][1]}</a>
215-
<a href="${url[3]}" title="${raw_url[4][2]}" role="button" rel="noreferrer noopener nofollow" class="btn btn-sm BtnGroup-item">${raw_url[4][1]}</a>
216-
`;
203+
html = ``;
204+
for (let i=0;i<url.length;i++)
205+
{
206+
html = html + `<a href="${url[i]}" title="${raw_url[i+1][2]}" role="button" rel="noreferrer noopener nofollow" class="btn btn-sm BtnGroup-item">${raw_url[i+1][1]}</a>`
207+
}
217208
$(this).after(html);
218209
});
219210
}
@@ -222,14 +213,14 @@
222213
// 添加 Raw 下载链接(☁)
223214
function addRawDownLink(){
224215
// 如果不是项目文件页面,就返回
225-
var files = $('div.Box-row svg.octicon.octicon-file');
216+
let files = $('div.Box-row svg.octicon.octicon-file');
226217
if(files.length === 0) return;
227-
var files1 = $('a.fileDownLink');
218+
let files1 = $('a.fileDownLink');
228219
if(files1.length > 0) return;
229220

230221
// 鼠标指向则显示
231222
var mouseOverHandler = function(evt){
232-
var elem = evt.currentTarget,
223+
let elem = evt.currentTarget,
233224
aElm_new = elem.querySelectorAll('.fileDownLink'),
234225
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.text-gray-light');
235226
aElm_new.forEach(el=>el.style.cssText = 'display: inline');
@@ -238,7 +229,7 @@
238229

239230
// 鼠标离开则隐藏
240231
var mouseOutHandler = function(evt){
241-
var elem = evt.currentTarget,
232+
let elem = evt.currentTarget,
242233
aElm_new = elem.querySelectorAll('.fileDownLink'),
243234
aElm_now = elem.querySelectorAll('svg.octicon.octicon-file.text-gray-light');
244235
aElm_new.forEach(el=>el.style.cssText = 'display: none');
@@ -247,12 +238,12 @@
247238

248239
// 循环添加
249240
files.each(function(i,fileElm){
250-
var trElm = fileElm.parentNode.parentNode,
241+
let trElm = fileElm.parentNode.parentNode,
251242
cntElm_a = trElm.querySelector('.css-truncate.css-truncate-target.d-block.width-fit a'),
252243
cntElm_svg = trElm.querySelector('.mr-3.flex-shrink-0 svg.octicon.octicon-file.text-gray-light'),
253244
Name = cntElm_a.innerText,
254245
href = cntElm_a.attributes['href'].nodeValue.replace('https://github.com','');
255-
var href2 = href.replace('/blob/','/'), url, url_name, url_tip = '';
246+
let href2 = href.replace('/blob/','/'), url, url_name, url_tip = '';
256247
switch(menu_raw_fast)
257248
{
258249
case 2:
@@ -271,7 +262,7 @@
271262
url_tip = raw_url[menu_raw_fast][2];
272263
break;
273264
}
274-
var html = ` <a href="${url}" download="${Name}" target="_blank" rel="noreferrer noopener nofollow" class="fileDownLink" style="display: none;" title="「${url_name}」&#10;&#10;[Alt + 左键] 或 [右键 - 另存为...] 下载文件。&#10;注意:鼠标点击 [☁] 图标,而不是左侧的文件名!&#10;&#10;${url_tip}提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ ${raw_url[menu_raw_fast][1]} ] 加速源 (☁) 即可切换。">${svg[2]}</a>`;
265+
let html = ` <a href="${url}" download="${Name}" target="_blank" rel="noreferrer noopener nofollow" class="fileDownLink" style="display: none;" title="「${url_name}」&#10;&#10;[Alt + 左键] 或 [右键 - 另存为...] 下载文件。&#10;注意:鼠标点击 [☁] 图标,而不是左侧的文件名!&#10;&#10;${url_tip}提示:点击浏览器右上角 Tampermonkey 扩展图标 - [ ${raw_url[menu_raw_fast][1]} ] 加速源 (☁) 即可切换。">${svg[2]}</a>`;
275266
$(cntElm_svg).after(html);
276267
// 绑定鼠标事件
277268
trElm.onmouseover=mouseOverHandler;
@@ -282,9 +273,9 @@
282273

283274
// 删除 Raw 快捷下载(☁)
284275
function delRawDownLink(){
285-
var aElm = document.querySelectorAll('.fileDownLink');
276+
let aElm = document.querySelectorAll('.fileDownLink');
286277
if(aElm.length === 0) return;
287-
for(var num = 0;num<aElm.length;num++){
278+
for(let num = 0;num<aElm.length;num++){
288279
aElm[num].remove();
289280
};
290281
}

0 commit comments

Comments
 (0)