Greasy Fork is available in English.

kinorium automatic theme

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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