User:Subh83/JavaScriptTools/RightclickMenus maintain.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Subh83/JavaScriptTools/RightclickMenus maintain. |
/****************************************************
* Created by Subhrajit Bhattacharya [[User:Subh83]] *
* Licensed under GNU-GPL v3.0 *
*****************************************************/
if (typeof(RightClickMenuKey)=='undefined') RightClickMenuKey = ''; // 'shift', 'alt', 'ctrl' or ''
function showMaintainMenu(e)
{
var menudiv = document.getElementById("maintainrightclickmenu");
if (!menudiv) {
alert("Unable to locate rightclick-menu!");
return false;
}
var posx = e.clientX;
var posy = e.clientY;
var w, h;
if (document.body && document.body.offsetWidth) {
w = document.body.offsetWidth;
h = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
document.documentElement &&
document.documentElement.offsetWidth ) {
w = document.documentElement.offsetWidth;
h = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
w = window.innerWidth;
h = window.innerHeight;
}
menudiv.style.position = "fixed";
if (posx < w/2) {
menudiv.style.left = posx+"px";
menudiv.style.pixelLeft = posx+"px";
menudiv.style.right = "auto";
menudiv.style.pixelRight = "auto";
} else {
menudiv.style.right = (w-posx)+"px";
menudiv.style.pixelRight = (w-posx)+"px";
menudiv.style.left = "auto";
menudiv.style.pixelLeft = "auto";
}
if (posy < h/2) {
menudiv.style.top = posy+"px";
menudiv.style.pixelTop = posy+"px";
menudiv.style.bottom = "auto";
menudiv.style.pixelBottom = "auto";
} else {
menudiv.style.bottom = (h-posy)+"px";
menudiv.style.pixelBottom = (h-posy)+"px";
menudiv.style.top = "auto";
menudiv.style.pixelTop = "auto";
}
if (!e) var e = window.event;
var rightclick;
if (e.which) rightclick = (e.which == 3);
else if (e.button) rightclick = (e.button == 2);
var keyPressed = true;
if (RightClickMenuKey=='' && (e.shiftKey || e.ctrlKey || e.altKey)) keyPressed = false;
else if (RightClickMenuKey=='shift' && !e.shiftKey) keyPressed = false;
else if (RightClickMenuKey=='ctrl' && !e.ctrlKey) keyPressed = false;
else if (RightClickMenuKey=='alt' && !e.altKey) keyPressed = false;
if (rightclick && keyPressed) {
menudiv.innerHTML = "<div style='font-size:8pt; background-color:#eee; border:2px outset #ccc; padding:3px; width:250px;'>RightclickMenus is currently under maintenance. Will be back soon! Sorry for the inconvenience.</div>";
menudiv.style.zIndex = "10000";
menudiv.style.display = "block";
return false;
}
else {
menudiv.style.display = "none";
return true;
}
}
addOnloadHook( function () {
// The right-click menu
var theBody = document.getElementsByTagName("body")[0];
if (theBody) {
theBody.onmouseup = showMaintainMenu;
theBody.oncontextmenu = showMaintainMenu;
}
var maintainrightclickmenu = document.createElement("div");
maintainrightclickmenu.setAttribute("id", "maintainrightclickmenu");
maintainrightclickmenu.setAttribute("display", "none");
theBody.insertBefore(maintainrightclickmenu, theBody.childNodes[0]);
});