Automatically switch the theme between light and dark, based on the browser's color scheme preference.
当前为
// ==UserScript==
// @name Auto Dark Mode for Hameln
// @name:zh-TW ハーメルン自動黑暗模式
// @description Automatically switch the theme between light and dark, based on the browser's color scheme preference.
// @description:zh-TW 基於瀏覽器的佈景主題設定,自動從明亮和黑暗模式間切換。
// @author Jason Kwok
// @namespace https://jasonhk.dev/
// @version 1.0.0
// @license MIT
// @match https://syosetu.org/*
// @run-at document-idle
// @grant none
// @supportURL https://greasyfork.org/scripts/449361/feedback
// ==/UserScript==
const toggle = document.getElementById("nightmode_check");
const query = window.matchMedia("(prefers-color-scheme: dark)");
query.addEventListener("change", updateDarkMode);
updateDarkMode(query);
function updateDarkMode({ matches })
{
if (toggle.checked !== matches)
{
toggle.click();
}
}