Last active
November 23, 2020 15:02
-
-
Save jangxx/dfb47c3dd8f1ee98cce067d5098733c3 to your computer and use it in GitHub Desktop.
A userscript which adds a "View" button to STL files on prusaprinters.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name PrusaPrinters STL Viewer | |
// @namespace http://literalchaos.de | |
// @version 1.0 | |
// @description Add a "View STL" button to prusaprinters.org | |
// @author jangxx | |
// @match https://www.prusaprinters.org/prints/* | |
// @grant none | |
// @downloadURL https://gist.github.com/jangxx/dfb47c3dd8f1ee98cce067d5098733c3/raw/prusaprinters_stl_viewer.user.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let currentlyInjected = false; | |
setInterval(function() { | |
const dlNode = document.querySelector("market-downloads"); | |
if (dlNode == undefined) { | |
currentlyInjected = false; | |
return; | |
} | |
if (currentlyInjected) return; | |
const dlItems = dlNode.querySelectorAll(".download-item"); | |
dlItems.forEach(elem => { | |
const downloadUrl = elem.querySelector(".btn-download").href; | |
const viewButton = document.createElement("a"); | |
viewButton.href = "https://3dviewer.net/#" + downloadUrl; | |
viewButton.target = "_blank"; | |
viewButton.className = "btn btn-primary"; | |
viewButton.innerHTML = `<i class="fa fa-eye"></i><span style="display: block; font-size: .6875rem;">View</span>`; | |
viewButton.style.cssText = "padding-bottom: .25rem; padding-top: 0; font-size: 1.25rem"; | |
const wrapper = document.createElement("div"); | |
wrapper.className = "download-wrapper"; | |
wrapper.style.marginRight = "0.2rem"; | |
wrapper.appendChild(viewButton); | |
elem.insertBefore(wrapper, elem.querySelector(".download-wrapper")); | |
}); | |
currentlyInjected = true; | |
}, 500); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment