Last active
June 6, 2024 01:46
-
-
Save westc/8544da8618c845f7219b033fc80ee013 to your computer and use it in GitHub Desktop.
Bookmarklet - Dark mode code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(()=>{ | |
const docElem = document.documentElement; | |
const FILTERS = [ | |
"", | |
"invert(1) hue-rotate(180deg) contrast(0.75)", | |
"invert(1) contrast(0.75)", | |
"invert(1) hue-rotate(180deg)" | |
]; | |
const VAR_NAME = "cwestDarkMode"; | |
const DATA_VAR_NAME = `data-${VAR_NAME.replace(/[A-Z]/g, '-$&').toLowerCase()}`; | |
let filterIndex = docElem.dataset[VAR_NAME]; | |
filterIndex = filterIndex | |
? (+filterIndex + 1) % FILTERS.length | |
: +(localStorage.getItem(VAR_NAME) || 1); | |
docElem.style.filter = FILTERS[filterIndex]; | |
// Store the data in local storage and in the docElem. | |
docElem.setAttribute(DATA_VAR_NAME, filterIndex); | |
localStorage.setItem(VAR_NAME, filterIndex); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.yourjs.com/tools/js-minifier/?input=js&output=bookmarklet&label=Dark+Mode