Greasy Fork is available in English.

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

< Σχολιασμός για τον κώδικα Disable YouTube number shortcuts

Ερώτηση/σχόλιο

§
Δημοσιεύτηκε: 10/04/2023

Hi, what about using isNaN instead of keys and keys.indexOf?

(function() {
    'use strict';

    (window.opera ? document.body : document).addEventListener('keydown', function(e) {
        if (isNaN(e.key) || e.isComposing || e.ctrlKey || e.altKey) return;
        e.cancelBubble = true;
        e.stopImmediatePropagation();
        return false;
    }, !window.opera);
})();
§
Δημοσιεύτηκε: 10/04/2023

I realised it also needs a e.key === ' ' condition

if (e.key === ' ' || isNaN(e.key) || e.isComposing || e.ctrlKey || e.altKey) return;`
§
Δημοσιεύτηκε: 20/01/2024

The source code is based on a very old stackoverflow post

Obviously this script is just created by newbie.

(function () {
    const keys = new Set('0123456789'.split(''));
    // keys.add(' '); // You can add other keys. Check in https://www.toptal.com/developers/keycode
    document.addEventListener('keydown', function (e) {
        if (keys.has(e.key) || e.isComposing || e.ctrlKey || e.altKey) return;
        e.stopPropagation();
        e.stopImmediatePropagation();
    }, true);
})();

Δημοσίευση απάντησης

Συνδεθείτε για να δημοσιεύσετε μια απάντηση.