Last active
July 8, 2023 00:31
-
-
Save eth-p/84609809239f320eb634d3e70f757ad1 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
// ==UserScript== | |
// @name Theme Color Sync for Google Calendar PWA | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Changes the window title to be the same color as the app background. Mostly useful for Dark Reader. | |
// @author eth-p | |
// @match https://calendar.google.com/* | |
// @icon https://calendar.google.com/googlecalendar/images/favicons_2020q4/calendar_31_256.ico | |
// @updateURL https://gist.github.com/eth-p/84609809239f320eb634d3e70f757ad1/raw/google-calendar-theme-sync.user.js | |
// @downloadURL https://gist.github.com/eth-p/84609809239f320eb634d3e70f757ad1/raw/google-calendar-theme-sync.user.js | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Get the theme-color meta element. | |
let themeColorMeta = document.querySelector('meta[name="theme-color"]'); | |
if (themeColorMeta == null) { | |
themeColorMeta = document.createElement("meta"); | |
themeColorMeta.setAttribute("name", "theme-color"); | |
document.head.appendChild(themeColorMeta); | |
} | |
function updateTheme() { | |
const computedStyles = window.getComputedStyle(document.body); | |
themeColorMeta.setAttribute("content", computedStyles.backgroundColor); | |
} | |
// Update the theme whenever the style changes. | |
window.addEventListener('load', updateTheme); | |
window.addEventListener('DOMContentLoaded', () => { | |
const observer = new MutationObserver(updateTheme); | |
observer.observe(document.body, { attributes: true, attributeFilter: ['class', 'style'] }); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment