Last active
May 12, 2019 11:05
-
-
Save aarongustafson/081d6e950c1f2cc57e22 to your computer and use it in GitHub Desktop.
A simple way to remove Bootstrap’s formatting and JavaScript influence
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
(function(){ | |
var body = document.body, | |
css = document.querySelectorAll('[href*=bootstrap][href$=css]'), | |
css_len = css.length, | |
js = document.querySelectorAll('[src*=bootstrap][src$=js]'), | |
js_len = js.length, | |
xhr = new XMLHttpRequest(), | |
strapped = false; | |
// Found Bootstrap CSS | |
if ( css_len ) { | |
// removing the CSS is easy | |
while ( css_len-- ) { | |
css[css_len].parentNode.removeChild(css[css_len]); | |
} | |
} | |
// Found Bootstrap JS | |
if ( js_len ) { | |
// resetting the HTML is more difficult | |
xhr.onload = function(){ | |
var new_body = this.responseXML.body; | |
// remove the scripts | |
while ( js_len-- ) { | |
js[js_len].parentNode.removeChild(js[js_len]); | |
} | |
body.parentNode.replaceChild( new_body, body ); | |
} | |
xhr.open('GET', window.location.href, true); | |
xhr.responseType = 'document'; | |
xhr.send(); | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment