巴哈姆特動畫瘋自動切換深色模式

根據系統配色自動開啟/關閉 ani.gamer.com.tw 的深色模式

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name                 BAHAMUT Auto Dark Mode
// @name:zh-CN           巴哈姆特动画疯自动切换深色模式
// @name:zh-TW           巴哈姆特動畫瘋自動切換深色模式
// @namespace            http://tampermonkey.net/
// @version              0.3
// @description          Turn on/off dark mode automatically in ani.gamer.com.tw based on the color scheme of OS.
// @description:zh-CN    根据系统配色自动开启/关闭 ani.gamer.com.tw 的深色模式
// @description:zh-TW    根據系統配色自動開啟/關閉 ani.gamer.com.tw 的深色模式
// @author               Jiachen Chen
// @match                *://ani.gamer.com.tw/*
// ==/UserScript==

(function () {
  "use strict";

  const htmlTag = document.getElementsByTagName("html")[0];
  const darkMode = document.getElementById("darkmode-moon");
  const lightMode = document.getElementById("darkmode-sun");

  if (window.matchMedia("(prefers-color-scheme: light)").matches) {
    if (darkMode.checked) {
      lightMode.click();
    }
  }

  window
    .matchMedia("(prefers-color-scheme: light)")
    .addEventListener("change", (e) => {
      if (e.matches && darkMode.checked) {
        lightMode.click();
      }
    });

  if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
    if (lightMode.checked) {
      darkMode.click();
    }
  }

  window
    .matchMedia("(prefers-color-scheme: dark)")
    .addEventListener("change", (e) => {
      if (e.matches && lightMode.checked) {
        darkMode.click();
      }
    });
})();