Added a link to download the branch as a ZIP file

This commit is contained in:
George Sokianos 2022-05-04 17:57:10 +01:00
parent 1e2ab13d1e
commit 23b694502d
1 changed files with 31 additions and 3 deletions

View File

@ -1,6 +1,6 @@
// GitHub CSS fixes
// version 1.0
// 2021-12-23
// version 1.1
// 2022-04-04
// Copyright (c) 2021 Created by Georgios Sokianos
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
@ -10,7 +10,7 @@
// @namespace none
// @description Fixes css in GitHub
// @include https://github.com/*
// @version $VER: GitHub CSS fixes 1.0 (23.12.2021)
// @version $VER: GitHub CSS fixes 1.1 (04.04.2022)
// @url https://ko-fi.com/walkero
// ==/UserScript==
@ -67,3 +67,31 @@ if (style.styleSheet){
style.appendChild(document.createTextNode(css));
}
window.onload = function () {
var canonicalElem = document.querySelector("link[rel='canonical']");
if (canonicalElem !== null) {
var canonicalUrl = canonicalElem.href;
var container = document.getElementById("repository-container-header");
var archiveText = document.createTextNode("Download ZIP");
var archiveUrl = canonicalUrl;
if (canonicalUrl.indexOf("tree") > -1) {
archiveUrl = archiveUrl.replace("tree", "archive/refs/heads");
} else {
var branchElem = document.querySelector("span[data-menu-button]");
if (branchElem !== null) {
archiveUrl += "/archive/refs/heads/" + branchElem.textContent;
}
}
if (archiveUrl != canonicalUrl) {
var archiveLink = document.createElement("a");
archiveLink.appendChild(archiveText);
archiveLink.title = "Download as a ZIP file";
archiveLink.href = archiveUrl + ".zip";
container.appendChild(archiveLink);
}
}
}