Skip to content

Instantly share code, notes, and snippets.

@splosch
Last active January 9, 2019 14:56
Show Gist options
  • Save splosch/22b310fbda68cb8cd4e5ebb087a971de to your computer and use it in GitHub Desktop.
Save splosch/22b310fbda68cb8cd4e5ebb087a971de to your computer and use it in GitHub Desktop.
Adds class "isSPContentPage" to body of webpages that are Sharepoint Content Pages - not so to Settings etc.
(function(){
var onDOMReady = function( fn ) {
if ( document.readyState !== 'loading' ) {
fn();
} else {
document.addEventListener( "DOMContentLoaded", fn );
}
},
markSPContentPages = function(){
var whitelist = [
'.welcome',
'#ctl00_PlaceHolderMain_WikiField'
],
containsMatchingSelector = function(selector){
return !!document.querySelector('#DeltaPlaceHolderMain > '+ selector);
};
if(whitelist.some(containsMatchingSelector)){
document.querySelector('body').classList.add('isSPContentPage');
}
};
onDOMReady(markSPContentPages);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment