Skip to content

Instantly share code, notes, and snippets.

@miya2000
Created October 11, 2012 07:17
Show Gist options
  • Save miya2000/3870736 to your computer and use it in GitHub Desktop.
Save miya2000/3870736 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Allow cursored context menu
// @description Allow script to receive right clicks only if the right clicked element's cursor is "context-menu".
// @include http://*
// == usage ==
// set true: opera:config#UserPrefs|Allowscripttoreceiverightclicks
// ==/UserScript==
(function() {
opera.addEventListener('BeforeEvent.contextmenu', function(e) {
const element = e.event.target;
const allow_context_menu = (function cursored(element) {
if (!element || element.nodeType != 1) {
return false;
}
const cursor = document.defaultView.getComputedStyle(element, '').cursor;
if (cursor == 'context-menu') {
return true;
}
return cursored(element.parentNode);
})(element);
if (!allow_context_menu) {
e.preventDefault();
}
}, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment