Disable YouTube number shortcuts

Stop the anoying 0 to 9 YouTube shortcuts from ruining your wathing experience while allowing all the other shortcuts to work

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Disable YouTube number shortcuts
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Stop the anoying 0 to 9 YouTube shortcuts from ruining your wathing experience while allowing all the other shortcuts to work
// @author       Éric Beaudoin (based on code by Martin J.H. from StackOverflow)
// @match        *://*.youtube.com/*
// @match        *://*.youtube.com
// @match        *://youtube.com/*
// @match        *://youtube.com
// @icon         https://www.google.com/s2/favicons?domain=youtube.com
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // The keys that we want to intercept (from keydownEvent.key)
    var keys = "0123456789";

    (window.opera ? document.body : document).addEventListener('keydown', function(e) {
        //console.log(`==> event.key: ${ e.key}, event.isComposing: ${ e.isComposing }, keys.indexOf(event.key): ${ keys.indexOf(e.key) } ` ); //uncomment to find more key
        if (keys.indexOf(e.key) != -1 && !(e.isComposing || e.ctrlKey || e.altKey)) {
            e.cancelBubble = true;
            e.stopImmediatePropagation();
            //console.log(`==> intercepted: ${ e.key }`);
        }
        return false;
    }, !window.opera);
})();