Skip to content

Instantly share code, notes, and snippets.

@jcartledge
Last active December 12, 2015 03:59
Show Gist options
  • Save jcartledge/4711389 to your computer and use it in GitHub Desktop.
Save jcartledge/4711389 to your computer and use it in GitHub Desktop.
count selectors
javascript:void(function(){
var _log = function() {
var args = $.makeArray(arguments).join(' ');
if(this.console) {
console.log(args);
} else {
alert(args);
}
};
var _count_selectors = function(sheet) {
var num_selectors;
var rules = $.makeArray(sheet.rules);
if(navigator.userAgent.match(/MSIE/)) {
return rules.length;
} else {
num_selectors = 0;
$.map(rules, function(rule) {
if(rule.selectorText !== undefined) {
num_selectors += rule.selectorText.split(/,/).length;
}
});
return num_selectors;
}
};
var _num_selectors, _total_selectors = 0;
$.map($.makeArray(document.styleSheets), function(sheet) {
if(sheet.href && sheet.href.match(/vu\.edu\.au/)) {
_total_selectors += _num_selectors = _count_selectors(sheet);
_log(sheet.href, ':', _num_selectors, ' selectors');
}
});
_log('Total selectors:', _total_selectors);
}());
javascript:void (function(){var c=function(){var e=$.makeArray(arguments).join(" ");if(this.console){console.log(e)}else{alert(e)}};var b=function(e){var f;var g=$.makeArray(e.rules);if(navigator.userAgent.match(/MSIE/)){return g.length}else{f=0;$.map(g,function(h){if(h.selectorText!==undefined){f+=h.selectorText.split(/,/).length}});return f}};var a,d=0;$.map($.makeArray(document.styleSheets),function(e){if(e.href&&e.href.match(/vu\.edu\.au/)){d+=a=b(e);c(e.href,":",a," selectors")}});c("Total selectors:",d)}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment