Auto Dark Mode for AniList Submission Manual

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

当前为 2023-02-15 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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            1.0.0
// @license            MIT
// @match              https://submission-manual.anilist.co/*
// @run-at             document-end
// @grant              none
// @supportURL         https://greasyfork.org/scripts/459664/feedback
// ==/UserScript==

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

query.addEventListener("change", updateTheme);

function isDarkTheme()
{
    return document.body.classList.contains("dark");
}

function updateTheme({ matches: isDarkMode })
{
    if (isDarkTheme() !== isDarkMode) { toggle(); }
}

// A patch to the otiginal `addDarkModeButton` to update the theme after the toggle was added.
const ogAddDarkModeButton = window.addDarkModeButton;
window.addDarkModeButton = function addDarkModeButton(device)
{
    ogAddDarkModeButton(device);
    updateTheme(query);
};