Skip to content

Instantly share code, notes, and snippets.

@eth-p
Last active July 8, 2023 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eth-p/84609809239f320eb634d3e70f757ad1 to your computer and use it in GitHub Desktop.
Save eth-p/84609809239f320eb634d3e70f757ad1 to your computer and use it in GitHub Desktop.
// ==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