kinorium automatic theme

Automatically applies a dark/light theme matching a system theme on kinorium.com

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name        kinorium automatic theme
// @name:ru     автоматическая тема для kinorium
// @description Automatically applies a dark/light theme matching a system theme on kinorium.com
// @description:ru Автоматически переключает темную/светлую тему на кинориуме в соответствии с системной темой
// @namespace   https://github.com/zenwarr
// @match       *://*.kinorium.com/*
// @grant       none
// @version     1.1
// @author      zenwarr
// @license     MIT
// ==/UserScript==

const mediaQuery = matchMedia("(prefers-color-scheme: dark)");
setTheme(mediaQuery.matches);
mediaQuery.addEventListener("change", q => setTheme(q.matches));

async function setTheme(isDark) {
  const newThemeName = isDark ? "dark" : "light";
  const autoTheme = $.cookie("autoTheme");
  const themeCookie = $.cookie("theme");

  if (autoTheme === "1" || !themeCookie || themeCookie !== newThemeName) {
    alert(`auto theme: switching to ${ newThemeName } theme`);

    $.get("/handlers/changeUserSettings/", { key: "event_autotheme", value: 0 }, () => {
      $.cookie("theme", newThemeName, {
        expires: 365,
        domain: "." + host,
        path: "/"
      });

      $.cookie("autoTheme", 0, {
        expires: 1,
        domain: "." + host,
        path: "/"
      });

      document.location.reload();
    }, "json");
  }
}