Skip to content

Instantly share code, notes, and snippets.

@furzeface
Last active December 31, 2015 04:28
Show Gist options
  • Save furzeface/7934044 to your computer and use it in GitHub Desktop.
Save furzeface/7934044 to your computer and use it in GitHub Desktop.
Removing GitHub Gists default styles from your <body> before styling them yourself.
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