Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TheColorman/9e78d97dc061cf754cfba6e451a55ee1 to your computer and use it in GitHub Desktop.
Save TheColorman/9e78d97dc061cf754cfba6e451a55ee1 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name AniList & AniChart System Theme - Dark/High Contrast
// @source https://gist.github.com/hotsno/9cbda7aaed334bb2c404a1834d4834ca
// @version 0.2
// @description Make AniList and AniChart follow your system theme. Instead of normal light mode, this script uses High Contrast.
// @author TheColorman
// @updateURL https://gist.githubusercontent.com/TheColorman/9e78d97dc061cf754cfba6e451a55ee1/raw/AniList-System-Theme-High-Contrast.user.js
// @downloadURL https://gist.githubusercontent.com/TheColorman/9e78d97dc061cf754cfba6e451a55ee1/raw/AniList-System-Theme-High-Contrast.user.js
// @supportURL https://gist.github.com/TheColorman/9e78d97dc061cf754cfba6e451a55ee1/
// @match https://anilist.co/*
// @match https://anichart.net/*
// @icon https://anilist.co/favicon.ico
// @grant none
// ==/UserScript==
(function() {
'use strict';
const switchTheme = (dark) => {
if (dark) {
document.body.classList.add('site-theme-dark');
document.body.classList.remove('site-theme-contrast');
} else {
document.body.classList.remove('site-theme-dark');
document.body.classList.add('site-theme-contrast');
}
}
const darkThemeMq = window.matchMedia("(prefers-color-scheme: dark)");
if (darkThemeMq.matches) {
setTimeout(function() {
switchTheme(true);
}, 100);
}
else {
setTimeout(function() {
switchTheme(false);
}, 100);
}
darkThemeMq.addListener(e => {
if (e.matches) {
switchTheme(true);
} else {
switchTheme(false);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment