Stop chapter skip shortcuts

Stop YouTube shortcuts from interfering with your Desktop environment workspace shortcuts

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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

})();