Automatic Theme Switcher

Automatically toggles between light and dark themes for KHInsider based on local time.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Automatic Theme Switcher
// @namespace    https://downloads.khinsider.com/
// @version      0.2
// @description  Automatically toggles between light and dark themes for KHInsider based on local time.
// @author       Inari
// @match        https://downloads.khinsider.com/*
// @grant        none
// @icon         https://cdn-icons-png.flaticon.com/512/543/543269.png
// ==/UserScript==

(function () {
    'use strict';
    if (window.location.pathname.includes('/forums')) {
        return;
    }
    const sunriseHour = 6; // 6:00 AM, change as needed
    const sunsetHour = 18; // 6:00 PM, change as needed
    const currentHour = new Date().getHours();
    const isDarkMode = currentHour >= sunsetHour || currentHour < sunriseHour;
    const url = new URL(window.location.href);
    const currentTheme = url.searchParams.get('theme');
    const desiredTheme = isDarkMode ? 'dark' : 'light';
    if (currentTheme !== desiredTheme) {
        url.searchParams.set('theme', desiredTheme);
        window.location.replace(url.toString());
    }
})();