Skip to content

Instantly share code, notes, and snippets.

@AsaAyers
Created April 8, 2015 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AsaAyers/eaf0d26a263b779a104d to your computer and use it in GitHub Desktop.
Save AsaAyers/eaf0d26a263b779a104d to your computer and use it in GitHub Desktop.
cssMonitor: ->
@selectors = []
for ss in document.styleSheets
for rule in ss.cssRules when rule.selectorText
@selectors.push(rule.selectorText)
@selectors.sort()
isUnused = (sel) ->
try
$(sel).length == 0
catch
return true
count = @selectors.length
setInterval((=>
@selectors = @selectors.filter(isUnused)
if count isnt @selectors.length
count = @selectors.length
console.warn('unused selectors', count)
), 1000)
getUnusedSelectors: -> @selectors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment