Created
February 16, 2009 16:01
-
-
Save stubbetje/65227 to your computer and use it in GitHub Desktop.
create list of unused stylesheet rules
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
// create list of unused stylesheet rules | |
$(document).ready(function() | |
{ | |
var sel = []; | |
for( var s = 0 ; s < document.styleSheets.length ; s++ ) { | |
var rules = document.styleSheets[s].cssRules || document.styleSheets[s].rules; | |
for( var r = 0 ; r < rules.length ; r++ ) { | |
if( rules[r].selectorText ) { | |
var pieces = rules[r].selectorText.split(','); | |
for( var p = 0 ; p < pieces.length ; p++ ) { | |
var selectorText = pieces[p].toLowerCase(); | |
try { | |
if( $( selectorText ).size() == 0 ) { | |
sel.push( $.trim(selectorText) ); | |
} | |
} catch( e ) { | |
console.log( selectorText ); | |
} | |
} | |
} | |
} | |
} | |
$(document.body).prepend( '<div class="std-msg-info"><em>Unused stylesheet rules:</em><pre>' + sel.join('\n') + '</pre></div>' ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment