Skip to content

Instantly share code, notes, and snippets.

@Jipok
Last active January 21, 2025 19:17
Show Gist options
  • Save Jipok/01d12591491816625649a467db898518 to your computer and use it in GitHub Desktop.
Save Jipok/01d12591491816625649a467db898518 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @run-at document-body
// ==/UserScript==
(function() {
'use strict';
const darkModeCSS = `
html {
filter: invert(90%) hue-rotate(180deg) !important;
}
img, video, picture {
filter: invert(100%) hue-rotate(180deg) !important;
}
`;
function handleThemeChange(e) {
const darkMode = document.getElementById('userscript-dark-mode');
if (e.matches) {
if (!darkMode) {
const darkModeStyle = document.createElement('style');
darkModeStyle.id = 'userscript-dark-mode';
darkModeStyle.innerHTML = darkModeCSS;
document.head.appendChild(darkModeStyle);
}
} else {
darkMode?.remove();
}
}
// Check for theme changes
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
darkModeMediaQuery.addListener(handleThemeChange);
handleThemeChange(darkModeMediaQuery);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment