Created
September 14, 2022 20:26
-
-
Save forivall/cf138d3aec675213d6e10d112c8186c4 to your computer and use it in GitHub Desktop.
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
javascript:(()=>{"function"==typeof window.__themeListenerUnsubscribe&&(window.__themeListenerUnsubscribe(),window.__themeListenerUnsubscribe=void 0);const e=window.matchMedia("(prefers-color-scheme: dark)"),t=async e=>{/255/.test(getComputedStyle(document.querySelector("#gbwa path")).getPropertyValue("color"))!==e.matches&&(async e=>{const t=e=>new Promise((t=>setTimeout(t,e)));var c=`[bgid="basic${e}"]:not(.a7J)`,o='[aria-label="Theme"] + button',n=document.querySelector(c),r=!n;if(!n){var i=document.querySelector(o);i||(document.querySelector('[data-tooltip="Settings"]').click(),await t(10),i=document.querySelector(o)),i.click(),await t(250),n=document.querySelector(c)}n.click(),r&&(await t(50),document.querySelector('[data-tooltip="Save & close"]').click())})(e.matches?"black":"white")};e.addEventListener("change",t),window.__themeListenerUnsubscribe=()=>{e.removeEventListener("change",t)}})() |
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
// changegmailtheme.js | |
/* env browser */ | |
/* global document */ | |
(() => { | |
const changeTheme = async (theme) => { | |
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
var themeOptionSelector = `[bgid="basic${theme}"]:not(.a7J)`; | |
var themeButtonSelector = '[aria-label="Theme"] + button'; | |
var themeOption = document.querySelector(themeOptionSelector); | |
var openDialog = !themeOption; | |
if (!themeOption) { | |
var themeButton = document.querySelector(themeButtonSelector); | |
if (!themeButton) { | |
document.querySelector('[data-tooltip="Settings"]').click(); | |
await wait(10); | |
themeButton = document.querySelector(themeButtonSelector); | |
} | |
themeButton.click(); | |
await wait(250); | |
themeOption = document.querySelector(themeOptionSelector); | |
} | |
themeOption.click(); | |
if (openDialog) { | |
await wait(50); | |
document.querySelector('[data-tooltip="Save & close"]').click(); | |
} | |
}); | |
if (typeof window.__themeListenerUnsubscribe === 'function') { | |
window.__themeListenerUnsubscribe(); | |
window.__themeListenerUnsubscribe = undefined; | |
} | |
const mediaQueryList = window.matchMedia("(prefers-color-scheme: dark)") | |
/** @param {MediaQueryListEvent} change */ | |
const listener = async (change) => { | |
const config = JSON.parse(await fsp.readFile(configFilename, 'utf8')); | |
const isDarkActive = /255/.test(getComputedStyle(document.querySelector("#gbwa path")).getPropertyValue('color')); | |
if (isDarkActive !== change.matches) { | |
changeTheme(change.matches ? 'black' : 'white'); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment