// ==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.0 // @author zenwarr // @license MIT // @downloadURL none // ==/UserScript== const mediaQuery = matchMedia("(prefers-color-scheme: dark)"); setTheme(mediaQuery.matches); mediaQuery.addEventListener("change", q => setTheme(q.matches)); async function setTheme(isDark) { const themeCookie = await cookieStore.get("theme"); const newThemeName = isDark ? "dark" : "light"; if (!themeCookie) { const expire = new Date().valueOf() + 1000 * 60 * 60 * 24 * 30; await cookieStore.set({ name: "theme", value: newThemeName, path: "/", sameSite: "strict", secure: true, expires: expire }); document.location.reload(); } else if (themeCookie.value !== newThemeName) { await cookieStore.set({ ...themeCookie, value: newThemeName }); document.location.reload(); } }