Stop chapter skip shortcuts

Stop YouTube shortcuts from interfering with your Desktop environment workspace shortcuts

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Stop chapter skip shortcuts
// @description  Stop YouTube shortcuts from interfering with your Desktop environment workspace shortcuts
// @version      1.0
// @author       JustBenDev
// @match        *://www.youtube.com/*
// @run-at       document-start
// @license      N/A
// @icon         https://www.youtube.com/favicon.ico
// @grant        none
// @namespace https://greasyfork.org/users/1499639
// ==/UserScript==

(function() {
    'use strict';

    const originalAddEventListener = EventTarget.prototype.addEventListener;
    EventTarget.prototype.addEventListener = function(type, listener, options) {
        if (type === 'keydown' || type === 'keyup') {
            const wrappedListener = function(e) {
                if (e.ctrlKey && (e.key === 'ArrowRight' || e.key === 'ArrowLeft')) {
                    console.log('[Stop chapter skip shortcuts.js] Blocked chapter skip');
                    e.stopImmediatePropagation();
                    e.preventDefault();
                    return false;
                }
                return listener.call(this, e);
            };
            return originalAddEventListener.call(this, type, wrappedListener, options);
        }
        return originalAddEventListener.call(this, type, listener, options);
    };

})();