Skip to content

Instantly share code, notes, and snippets.

@sweatpantsninja
Last active December 16, 2015 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sweatpantsninja/5400379 to your computer and use it in GitHub Desktop.
Save sweatpantsninja/5400379 to your computer and use it in GitHub Desktop.
How to remove :hover styles from your stylesheets without messing up complex, useful rules like: .ok, .not-ok:hover, .also-ok { ... } FYI relies on UnderscoreJS to user _.reject(), but that's clearly a writable function
if 'createTouch' of document
ignore = /:hover\b/
try
for stylesheet in document.styleSheets
idxsToDelete = []
# detect hover rules
for rule, idx in stylesheet.cssRules
if rule.type is CSSRule.STYLE_RULE and ignore.test(rule.selectorText)
newSelector = _.reject rule.selectorText.split(","), (s) -> ignore.test s
if newSelector.length > 0
newRule = newSelector.join(",").concat rule.cssText.substr(rule.cssText.indexOf("{"))
stylesheet.deleteRule idx
stylesheet.insertRule newRule, idx
else
idxsToDelete.unshift idx
# delete hover rules
stylesheet.deleteRule idx for idx in idxsToDelete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment