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
// Get the initial state | |
const query = window.matchMedia('(prefers-color-scheme: dark)'); | |
function toggleDarkMode(toggle = query.matches) { | |
// Open the menu | |
document.querySelector('#USER_DROPDOWN_ID[aria-expanded="false"]')?.click(); | |
// Get the wrapper item | |
const wrapper = Array.from(document.querySelectorAll('button')).find(({ innerText }) => innerText.toLowerCase() === 'dark mode'); | |
const checkbox = wrapper?.querySelector(`[aria-checked="${!toggle}"]`); |
OlderNewer