Youtube Video Flip Toggle

Toggle horizontal flip on video elements

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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