Ozon Simple Dark Mode Support

Добавляет поддержку тёмной темы

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.

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.

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

// ==UserScript==
// @name         Ozon Simple Dark Mode Support
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Добавляет поддержку тёмной темы
// @author       Jipok
// @match        *://*.ozon.ru/*
// @license MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
        const darkModeCSS = `
            html {
                filter: invert(90%) hue-rotate(180deg) !important;
            }

            img, video, picture {
                filter: invert(100%) hue-rotate(180deg) !important;
            }
        `;

    function handleThemeChange(e) {
        const darkMode = document.getElementById('ozon-dark-mode');

        if (e.matches) {
            if (!darkMode) {
                const darkModeStyle = document.createElement('style');
                darkModeStyle.id = 'ozon-dark-mode';
                darkModeStyle.innerHTML = darkModeCSS;
                document.head.appendChild(darkModeStyle);
            }
        } else {
            darkMode?.remove();
        }
    }

    // Check for theme changes
    const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
    darkModeMediaQuery.addListener(handleThemeChange);

    handleThemeChange(darkModeMediaQuery);
})();