Prevent contextmenu hijack

Removes all listeners to the contextmenu event

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Prevent contextmenu hijack
// @namespace    http://github.com/kba
// @version      0.1
// @description  Removes all listeners to the contextmenu event
// @author       kba
// @match        */*
// @grant        GM_registerMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==
/* jshint -W097 */
/* globals GM_getValue, GM_setValue, GM_registerMenuCommand */
'use strict';


function removeContextMenuListeners() {
	document.oncontextmenu = null;
	var elems = document.querySelectorAll('div,img,video,figure,main,article,section,header,footer');
	for (var i = 0 ; i < elems.length ; i++) {
		elems[i].oncontextmenu = null;
	}
}

function isPermanent() { return GM_getValue('permanent'); }
function togglePermanent() { GM_setValue('permanent', ! isPermanent()); }

if (isPermanent()) {
	setTimeout(removeContextMenuListeners, 500);
}

GM_registerMenuCommand('Allow Right-Click', removeContextMenuListeners);
GM_registerMenuCommand((isPermanent() ? 'Dis' : 'En') +  'able Permanent Allow Right-Click', togglePermanent);