I wrote this script a while back that's worked better for me than any other right-click-enabling extension.
function rightClickEvent(event) {
event.stopPropagation();
return true;
}
function enableRightClick(elements) {
if (elements.length === 0) return;
Array.prototype.slice.call(elements, 0).forEach(element => {
element.addEventListener('contextmenu', rightClickEvent, true);
enableRightClick(element.children);
});
}
enableRightClick(document.children);
It seems like overkill because it adds an action listener to every single element on the whole page. Is there any way to achieve similar results, like a way to intercept every event for oncontextmenu
, without having to traverse the DOM of the entire page?
To clarify, this is for ENABLING right click in environments where a simple change of contextmenu on the button doesn't work.