Youtube Video Flip Toggle

Toggle horizontal flip on video elements

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

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

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         Youtube Video Flip Toggle
// @namespace    https://greasyfork.org/en/users/807108-jeremy-r
// @version      1.1
// @description  Toggle horizontal flip on video elements
// @match        https://www.youtube.com/watch?v=*
// @grant        GM_registerMenuCommand
// @author       JRem
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    let flipped = false;
    let observer = null;

    function applyFlip(video) {
        video.style.transform = flipped ? 'scaleX(-1)' : 'scaleX(1)';
    }

    function toggleFlip() {
        const video = document.querySelector('video');
        if (!video) {
            alert("No <video> element found on this page.");
            return;
        }

        flipped = !flipped;
        applyFlip(video);

        if (flipped && !observer) {
            // Watch for style resets
            observer = new MutationObserver(() => {
                applyFlip(video);
            });
            observer.observe(video, { attributes: true, attributeFilter: ['style'] });
        } else if (!flipped && observer) {
            observer.disconnect();
            observer = null;
        }
    }

    GM_registerMenuCommand("Toggle Video Flip", toggleFlip);
})();