Skip to content

Instantly share code, notes, and snippets.

@lwcorp
Forked from frontdevops/darkthemeswitcher-inline.js
Last active June 16, 2026 15:18
Show Gist options
  • Select an option

  • Save lwcorp/4192f00cfc52c243e007f47a30aa6935 to your computer and use it in GitHub Desktop.

Select an option

Save lwcorp/4192f00cfc52c243e007f47a30aa6935 to your computer and use it in GitHub Desktop.
Bookmarklet - Simple Dark Theme for web pages, but without: 1) Affecting iframes (like embedded YouTube) 2) Images that use background-image= instead of <img 3) Outdated style type
javascript:(d=>{var css=`:root{background-color:#fefefe;filter:invert(100%)}iframe,[style*="background-image:"]:not([style$=".svg)"]),img:not([src*=".svg"]),video{filter:invert(100%)}`,style,id="dark-theme-snippet",ee=d.getElementById(id);if(null!=ee)ee.parentNode.removeChild(ee);else{style=d.createElement('style');style.id=id;if(style.styleSheet)style.styleSheet.cssText=css;else style.appendChild(d.createTextNode(css));(d.head||d.querySelector('head')).appendChild(style);}})(document)
(d=>{
var css = `
:root{
background-color: #fefefe;
filter: invert(100%)
}
/* * {
background-color: inherit
}*/
iframe, [style*="background-image:"]:not([style$=".svg)"]), img:not([src*=".svg"]), video{
filter: invert(100%)
}
`,
style,
id="dark-theme-snippet",
ee = d.getElementById(id);
if (null != ee) ee.parentNode.removeChild(ee);
else {
style = d.createElement('style');
style.id = id;
if (style.styleSheet) style.styleSheet.cssText = css;
else style.appendChild(d.createTextNode(css));
(d.head||d.querySelector('head')).appendChild(style);
}
})(document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment