Skip to content

Instantly share code, notes, and snippets.

@kageurufu
Created February 28, 2022 17:26
Show Gist options
  • Save kageurufu/c7ea1e8e822f4897c2e9d94bece5ad50 to your computer and use it in GitHub Desktop.
Save kageurufu/c7ea1e8e822f4897c2e9d94bece5ad50 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Thingiverse Zip Button
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.thingiverse.com/thing:*
// @icon https://www.google.com/s2/favicons?sz=64&domain=thingiverse.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
function addDownloadZipLink() {
const downloadAllLink = document.querySelector('[class^="SidebarMenu__download"]');
const downloadContainer = downloadAllLink.parentElement;
if(downloadContainer.dataset.hasZipLink) return;
const thingId = document.location.pathname.match(/thing:(\d*)/)[1];
const zipImage = document.createElement('img');
zipImage.src = 'https://upload.wikimedia.org/wikipedia/commons/b/be/Octicons-file-zip.svg';
zipImage.height = 24;
zipImage.style.float = 'left';
zipImage.style.filter = 'invert(1)';
zipImage.style.padding = '3px 8px';
const button = document.createElement('div');
button.className = 'button button-primary';
button.style.textAlign='left';
button.style.fontWeight = '600';
button.appendChild(zipImage)
button.append("Download as Zip File");
const link = document.createElement('a');
link.className = downloadAllLink.className;
link.href = `/thing:${thingId}/zip`
link.appendChild(button);
downloadContainer.prepend(link);
downloadAllLink.firstChild.style.opacity = '30%';
downloadContainer.dataset.hasZipLink = true;
}
const observer = new MutationObserver(addDownloadZipLink)
observer.observe(document.body, {childList:true, subtree:true});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment