Auto Dark Mode for AniList Submission Manual

Automatically switch the theme between light and dark, based on the browser’s color scheme preference.

// ==UserScript==
// @name               Auto Dark Mode for AniList Submission Manual
// @name:zh-TW         AniList 投稿指引自動黑暗模式
// @description        Automatically switch the theme between light and dark, based on the browser’s color scheme preference.
// @description:zh-TW  根據瀏覽器的佈景主題設定,自動從明亮和黑暗模式間切換。
// @icon               https://icons.duckduckgo.com/ip3/submission-manual.anilist.co.ico
// @author             Jason Kwok
// @namespace          https://jasonhk.dev/
// @version            2.0.0
// @license            MIT
// @match              https://submission-manual.anilist.co/*
// @run-at             document-end
// @inject-into        page
// @grant              none
// @supportURL         https://greasyfork.org/scripts/459664/feedback
// ==/UserScript==

const isGreasemonkey = (GM.info.scriptHandler === "Greasemonkey");

if (isGreasemonkey)
{
    window.onLight = window.eval("onLight");
    window.onDark = window.eval("onDark");
}

const query = matchMedia("(prefers-color-scheme: dark)");

function toggle()
{
    query.matches ? onDark() : onLight();
}

if (isGreasemonkey)
{
    exportFunction(toggle, window, { defineAs: "toggle" });
}
else
{
    window.toggle = toggle;
}