Scriptbar Snippets 🚀
Handy and easy to understand snippets to keep in your browser
insert-css.js

#Basic

Insert css into current page DOM

Insert CSS into current page DOM

Example

  • Run insertCss("html{filter: invert(1)}") to turn light theme website to dark theme
/* * Expose method insertCss allow to insert css code into the DOM * Example: insertCss(`html{filter: invert(1)}`) */ ((root, document) => { function insertCss(code) { if (!code) { return console.error('insertCss: No code'); } var style = document.createElement('style'); if (style.styleSheet) { // IE style.styleSheet.cssText = code; } else { // Other browsers style.innerHTML = code; } document.getElementsByTagName("head")[0].appendChild( style ); } root.insertCss = insertCss; })(this, document)
Built with ❤️ by @domnguyen and everyone on the internet 🚀