Last active
December 31, 2015 04:28
-
-
Save furzeface/7934044 to your computer and use it in GitHub Desktop.
Removing GitHub Gists default styles from your <body> before styling them yourself.
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
var domLinks = document.getElementsByTagName('link'); // Get all the <link>'s | |
// Will most likely find stylesheets but will find any with rels eg rel="canonical/author/external..." | |
// Unfortunately we can't just traverse the <head> as the Gist stylesheet is embedding with the Gist in your pages <body> | |
var gistLinks = []; | |
for (var i = 0, l = domLinks.length; i < l; i++) {//loop 'em | |
var el = domLinks[i]; //current link | |
// If 'gist' is in the href - | |
if (el.href.indexOf('gist') > -1) { | |
gistLinks.push(el); | |
} | |
} | |
// Going through the array, removing the linked stylesheets | |
gistLinks.forEach(function (gistLink) { | |
gistLink.parentNode.removeChild(gistLink); // Remove the embedded stylesheet and style away! | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment