Last active
June 29, 2016 04:35
-
-
Save darktrojan/1f7fdf18980bac7ec518ed1ae9408f4e to your computer and use it in GitHub Desktop.
Scratchpad for detecting unused CSS rules
This file contains hidden or 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
var script = 'data:text/plain,' + encodeURIComponent(` | |
let DOMUtils = Components.classes['@mozilla.org/inspector/dom-utils;1'].getService(Components.interfaces.inIDOMUtils); | |
for (let ss of content.document.styleSheets) { | |
if (content.matchMedia(ss.media.mediaText).matches) { | |
content.console.log(ss); | |
for (let r of ss.cssRules) { | |
rule(r); | |
} | |
} | |
} | |
function rule(r) { | |
if (r.selectorText) { | |
try { | |
for (let s of r.selectorText.split(',')) { | |
let t = s.replace(/:(hover|:before|:after)/, ''); | |
if (!content.document.querySelector(t)) { | |
content.console.log('[' + DOMUtils.getRuleLine(r) + '] ' + s.trim()); | |
} | |
} | |
} catch (ex) { | |
content.console.error(ex); | |
} | |
} else if (r instanceof content.CSSMediaRule && content.matchMedia(r.conditionText).matches) { | |
content.console.log(r); | |
for (let rr of r.cssRules) { | |
rule(rr); | |
} | |
} | |
} | |
`); | |
gBrowser.selectedBrowser.messageManager.loadFrameScript(script, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment