Skip to content

Instantly share code, notes, and snippets.

@depoulo
Last active May 22, 2017 14:14
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 depoulo/4bf34a423ec320c38eda to your computer and use it in GitHub Desktop.
Save depoulo/4bf34a423ec320c38eda to your computer and use it in GitHub Desktop.
Add CSS rules quickly from the browser JS console. Idea taken from http://davidwalsh.name/add-rules-stylesheets
(() => {
var style = document.createElement("style");
style.appendChild(document.createTextNode(""));
document.head.appendChild(style);
var rules = prompt('Paste CSS rules here');
var importStatements = (rules.split(';') || []).filter(s => s.startsWith('@import')).map(s => s + ';');
importStatements.forEach((importStatement, index) => style.sheet.insertRule(importStatement, index));
style.sheet.insertRule(`@media all{${rules}`, importStatements.length);
}())
@depoulo
Copy link
Author

depoulo commented Apr 8, 2015

Bookmarklet:

javascript:(()=>{var e=document.createElement("style");e.appendChild(document.createTextNode(""));document.head.appendChild(e);var t=prompt('Paste CSS rules here'),r=(t.split(';')||[]).filter(e=>e.startsWith('@import')).map(e=>e+';');r.forEach((t,r)=>e.sheet.insertRule(t,r));e.sheet.insertRule(`@media all{${t}`,r.length)})()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment