Youtube Video Flip Toggle

Toggle horizontal flip on video elements

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 or Violentmonkey 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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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         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);
})();