update:
To detect youtube page change and inject the script
document.body.addEventListener("yt-navigate-finish", function (event) {
console.log('Youtube page Change')
$('div video').addEventListener('contextmenu', e => e.preventDefault());
$('body').insertAdjacentHTML('afterbegin', '<style>.ytp-contextmenu{visibility:hidden;}</style>');
});
you can try this
// disable HTML5 Video contextmenu
$('div video').addEventListener('contextmenu', e=>e.preventDefault())
// hide element contextmenu by appending custom <style> (CSS)
// cannot use inline CSS
// because the element created after user right click
$('body').insertAdjacentHTML('afterbegin', '<style>.ytp-contextmenu{visibility:hidden;}</style>');
$()
is not jQuery function, change it with document.querySelector()
if you have trouble