Created
December 29, 2022 07:29
-
-
Save IdrisQe/e4532285d916408acc217a49d56605bc to your computer and use it in GitHub Desktop.
Automatic Google Dark Mode UserScript (v2.1)
This file contains hidden or 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
| // ==UserScript== | |
| // @name Google Dark Mode Auto-Enable | |
| // @description Make Google go dark automatically | |
| // @version 2.1 | |
| // @author IdrisQe | |
| // @match *://*.google.com/* | |
| // @match *://*.google.ca/* | |
| // @run-at document-start | |
| // @inject-into page | |
| // ==/UserScript== | |
| let darkModeIsOn = false; | |
| const timer = setInterval(tryDarkMode, 20); | |
| function tryDarkMode() { | |
| if (!darkModeIsOn) { | |
| if (document.readyState === 'complete') { | |
| try { | |
| let darkModeButton = document.querySelector('#YUIDDb > div'); | |
| if (!darkModeButton) { | |
| let radialButton = document.querySelector('g-radio-button-group > div[data-index="1"] > div:nth-child(2)'); | |
| if (radialButton) { | |
| const radialButtonStyleMatrixArray = window.getComputedStyle( | |
| document.querySelector('g-radio-button-group > div[data-index="1"] > div:nth-child(2)')).getPropertyValue('transform').match(/(-?[0-9\.]+)/g); | |
| if (radialButtonStyleMatrixArray[0] === '0') { | |
| darkModeIsOn = true; | |
| document.querySelector('g-radio-button-group > div[data-index="1"]').click(); | |
| } | |
| } | |
| } else if (darkModeButton.textContent === 'Dark theme: Off') { | |
| darkModeIsOn = true; | |
| darkModeButton.click(); | |
| } | |
| } catch { | |
| return; | |
| } | |
| } | |
| } else { | |
| clearInterval(timer); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment