Skip to content

Instantly share code, notes, and snippets.

@Ryan1729
Last active July 1, 2020 14:49
Show Gist options
  • Save Ryan1729/e7394e02d7476889a4d76d9670d9f169 to your computer and use it in GitHub Desktop.
Save Ryan1729/e7394e02d7476889a4d76d9670d9f169 to your computer and use it in GitHub Desktop.
The nuclear option for when a page does not have a dark mode

Nuclear Dark Mode

Open the browser console and paste the contents of nuclearDarkMode.js inside it.

Known bugs

  • iframes apparently cannot have their styles set by the host page, and are instead removed entirely. Some pages have content in iframes.
  • pseudo-elements may still have bright background colors. Is there a reasonable way to fix this?
var nuclearDarkMode = (root = document, seen = {}) => {
if (seen[root]) {
return;
}
seen[root] = true
var items = root.getElementsByTagName("*");
for (var i = items.length; i--;) {
var item = items[i]
item.style["background-color"] = "#222"
item.style["color"] = "#eee"
if (item.nodeName == "IFRAME") {
item.parentNode.removeChild(item)
}
nuclearDarkMode(root, seen)
}
}
nuclearDarkMode()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment