kinorium automatic theme

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

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

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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");
  }
}