Automatic Theme Switcher

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

目前為 2024-12-14 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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());
    }
})();