Skip to content

Commit f69f696

Browse files
author
Hale Shaw
committed
Add download ZIP button
1 parent 9679ac9 commit f69f696

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

GitHubMirror.user.js

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// @description GitHub镜像,加速访问GitHub,支持Clone、Release、Raw、Zip加速。
55
// @description:en GitHub mirror. Accelerate access to GitHub. Support Clone, Release, RAW and ZIP acceleration.
66
// @namespace https://github.com/HaleShaw
7-
// @version 1.1.0
7+
// @version 1.2.0
88
// @author HaleShaw
99
// @copyright 2021+, HaleShaw (https://github.com/HaleShaw)
1010
// @license AGPL-3.0-or-later
@@ -187,6 +187,9 @@
187187
if (location.pathname.split('/')[3] == 'releases') {
188188
addReleasesList();
189189
}
190+
if (isPC) {
191+
addDownloadZip();
192+
}
190193
}
191194

192195
/**
@@ -410,6 +413,9 @@
410413
</a>`;
411414
}
412415

416+
/**
417+
* Add Release list.
418+
*/
413419
function addReleasesList() {
414420
$('.Box--condensed')
415421
.find('[href]')
@@ -422,14 +428,45 @@
422428
});
423429
}
424430

431+
/**
432+
* Get Release download button html string.
433+
* @param {String} href href.
434+
* @returns html.
435+
*/
425436
function getReleaseDownloadHtml(href) {
426-
let span = '';
437+
let html = '';
427438
downloadSet.forEach(id => {
428-
span += `<a class="flex-1 btn btn-outline get-repo-btn" rel="nofollow" href="${
439+
html += `<a class="flex-1 btn btn-outline get-repo-btn" rel="nofollow" href="${
429440
mirrors[id]['url'] + href
430441
}" title="${mirrors[id]['description']}">${mirrors[id]['name']}</a>`;
431442
});
432-
return span;
443+
return html;
444+
}
445+
446+
/**
447+
* Add download zip button.
448+
*/
449+
function addDownloadZip() {
450+
$("a[data-open-app='link']").each(function () {
451+
var li = $(`<li class="Box-row p-0"></li>`);
452+
const downloadHref = $(this).attr('href');
453+
var aElement = $(this)
454+
.clone()
455+
.removeAttr('data-hydro-click data-hydro-click-hmac data-ga-click');
456+
aElement.addClass('Box-row Box-row--hover-gray');
457+
downloadSet.forEach(id => {
458+
let tempA = aElement.clone();
459+
tempA.attr({
460+
href: mirrors[id]['url'] + downloadHref,
461+
title: mirrors[id]['description']
462+
});
463+
tempA.html(
464+
tempA.html().replace('Download ZIP', `Download ZIP(${mirrors[id]['name']})`)
465+
);
466+
li = li.clone().append(tempA);
467+
});
468+
$(this).parent().after(li);
469+
});
433470
}
434471

435472
/**

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ GitHub镜像,加速访问GitHub,支持Clone、Release、Raw、Zip加速。
4444

4545
![GitHubMirror_Release](https://raw.githubusercontent.com/HaleShaw/TM-GitHubMirror/master/Screenshots/GitHubMirror_Release.png)
4646

47+
### 下载ZIP
48+
49+
![GitHubMirror_DownloadZIP](https://raw.githubusercontent.com/HaleShaw/TM-GitHubMirror/master/Screenshots/GitHubMirror_DownloadZIP.png)
50+
4751
## 贡献者
4852

4953
- [<img src="https://greasyfork.org/packs/media/images/blacklogo16-5421a97c75656cecbe2befcec0778a96.png" width="32px" height="32px"/>码酷](https://greasyfork.org/zh-CN/scripts/383577)
@@ -96,6 +100,11 @@ This function script has been updated in several versions since its birth.But as
96100

97101
![GitHubMirror_Release](https://raw.githubusercontent.com/HaleShaw/TM-GitHubMirror/master/Screenshots/GitHubMirror_Release.png)
98102

103+
### Download ZIP
104+
105+
![GitHubMirror_DownloadZIP](https://raw.githubusercontent.com/HaleShaw/TM-GitHubMirror/master/Screenshots/GitHubMirror_DownloadZIP.png)
106+
107+
99108
## Contributors
100109

101110
- [<img src="https://greasyfork.org/packs/media/images/blacklogo16-5421a97c75656cecbe2befcec0778a96.png" width="32px" height="32px"/>码酷](https://greasyfork.org/zh-CN/scripts/383577)
32.5 KB
Loading

0 commit comments

Comments
 (0)