Stop chapter skip shortcuts

Stop YouTube shortcuts from interfering with your Desktop environment workspace shortcuts

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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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

})();