Created
January 23, 2022 19:33
-
-
Save mosherbrian/a687614439bafae619be25a4179eb249 to your computer and use it in GitHub Desktop.
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 Gist HTML Live Preview | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Display a button on GitHub Gist HTML files to preview the file using https://raw.githack.com to serve the page in developer mode. | |
// @author Brian Mosher | |
// @match https://gist.github.com/* | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let rawBtnLinks = document.querySelectorAll("div .file-actions > a"); | |
for (let link of rawBtnLinks) | |
{ | |
let rawURL = link.href; | |
let urlExtension = rawURL.split('.').pop(); | |
if ( urlExtension.toLowerCase() === 'html' || urlExtension.toLowerCase() === 'htm' ) | |
{ | |
let newPreviewLink = link.cloneNode(); | |
newPreviewLink.textContent = "Preview"; | |
newPreviewLink.href = newPreviewLink.href.replace("gist.github.com", "gist.githack.com"); | |
link.parentElement.appendChild(newPreviewLink); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment