MediaWiki:Gadget-MediaLoaderContext.js

String.prototype.replaceAll = function (search, replacement) { var target = this; return target.split(search).join(replacement); }; //Had to do a one line string due to MediaWiki JS restrictions var contextmenu = " File not set Open file page Open file page in new tab "; //I know I could avoid some lines but I don't really want to change how it is var el = document.createElement("div"); el.innerHTML = contextmenu; document.body.append(el); $(".MediaLoader").contextmenu(function (e) {   if (e.target.tagName != "DIV") {        return;    }    $(".-context-menu").css("display", "block")        .css("top", e.pageY)        .css("left", e.pageX);    $(".-context-menu-media-load-file").text($(e.target).parent.parent.data("file"));    e.preventDefault;    return false; }); $(document).click(function (e) {   var t = $(e.target);    if (t.hasClass("-context-menu-text") || t.hasClass("-context-menu-item")) {        return;    }    $(".-context-menu").css("display", "none") }) $(document).contextmenu(function (e) {   $(".-context-menu").css("display", "none") }) $(".-context-menu-media-load-open").click(function (e) { window.location = "/wiki/" + e.target.previousSibling.innerText }) $(".-context-menu-media-load-tab").click(function (e) { window.open("/wiki/" + e.target.previousSibling.previousSibling.innerText) })