Automatic Theme Switcher

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

  1. // ==UserScript==
  2. // @name Automatic Theme Switcher
  3. // @namespace https://downloads.khinsider.com/
  4. // @version 0.2
  5. // @description Automatically toggles between light and dark themes for KHInsider based on local time.
  6. // @author Inari
  7. // @match https://downloads.khinsider.com/*
  8. // @grant none
  9. // @icon https://cdn-icons-png.flaticon.com/512/543/543269.png
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14. if (window.location.pathname.includes('/forums')) {
  15. return;
  16. }
  17. const sunriseHour = 6; // 6:00 AM, change as needed
  18. const sunsetHour = 18; // 6:00 PM, change as needed
  19. const currentHour = new Date().getHours();
  20. const isDarkMode = currentHour >= sunsetHour || currentHour < sunriseHour;
  21. const url = new URL(window.location.href);
  22. const currentTheme = url.searchParams.get('theme');
  23. const desiredTheme = isDarkMode ? 'dark' : 'light';
  24. if (currentTheme !== desiredTheme) {
  25. url.searchParams.set('theme', desiredTheme);
  26. window.location.replace(url.toString());
  27. }
  28. })();