Skip to content

Instantly share code, notes, and snippets.

@ahvonenj
Last active August 17, 2018 02:17
Show Gist options
  • Save ahvonenj/a50bed986634211c8eb18859e7ea44b9 to your computer and use it in GitHub Desktop.
Save ahvonenj/a50bed986634211c8eb18859e7ea44b9 to your computer and use it in GitHub Desktop.
[TamperMonkey] Download all files of commit -- Adds a custom button to github commit view pages from which all the changed files can be downloaded. Useful for when something is removed from a repository and only the commit information remains.
// ==UserScript==
// @name Github commit files downloader
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://github.com/*/*/commit/*
// @grant none
// ==/UserScript==
(function()
{
'use strict';
function DownloadAll()
{
var fileLinks = Array.prototype.slice.call(
document.querySelectorAll('div.file-header.js-file-header > div.file-actions > a')
).map(x => x.href);
for(var i = 0; i < fileLinks.length; i++)
{
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent('https://minhaskamal.github.io/DownGit/#/home?url=' + fileLinks[i]));
element.setAttribute('download', fileLinks[i].substring(fileLinks[i].lastIndexOf('/') + 1));
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
}
function htmlToElement(html)
{
var template = document.createElement('template');
html = html.trim();
template.innerHTML = html;
return template.content.firstChild;
}
document
.querySelector('#js-repo-pjax-container > div.container.new-discussion-timeline.experiment-repo-nav > div.repository-content > div.full-commit')
.prepend(
htmlToElement('<button class="btn btn-outline float-right" style = "margin-left: 10px;" id = "CustomDLButton">Download files</button>')
);
document.getElementById("CustomDLButton").addEventListener("click", DownloadAll);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment