From 23b694502dfc025a9960d165d28b0c2fcd2a0a54 Mon Sep 17 00:00:00 2001 From: George Sokianos Date: Wed, 4 May 2022 17:57:10 +0100 Subject: [PATCH] Added a link to download the branch as a ZIP file --- github.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/github.js b/github.js index 471a861..42ecbde 100644 --- a/github.js +++ b/github.js @@ -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); + } + } +} +