Skip to content

Instantly share code, notes, and snippets.

@esprehn
Last active September 1, 2016 04:18
Show Gist options
  • Save esprehn/319d1db9ed833fca786691a5140aee3f to your computer and use it in GitHub Desktop.
Save esprehn/319d1db9ed833fca786691a5140aee3f to your computer and use it in GitHub Desktop.
Find all the pseudos
(function() {
var selectors = new Map();
for (let sheet of Array.from(document.styleSheets)) {
for (let rule of Array.from(sheet.cssRules || [])) {
var text = rule.selectorText || "";
for (let match of (text.match(/\:([a-zA-Z0-9\-]+)/g) || []))
selectors.set(match, (selectors.get(match) || 0) + 1);
}
}
return [
selectors,
// We need to allocate each one at least once, so subtract the set size.
Array.from(selectors.values()).reduce((total, value) => total + value, 0) - selectors.size,
];
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment