kinorium automatic theme

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

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

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

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

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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