Prevent contextmenu hijack

Removes all listeners to the contextmenu event

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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);