User:Thatawesomecat/global.js

document.addEventListener("keyup", function(e) {

var pageName = mw.config.get("wgRelevantPageName"),

articlePath = mw.config.get("wgArticlePath").replace("$1", pageName),

currentAction = mw.config.get("wgAction"),

editPage = articlePath + "?veaction=editsource",

deletePage = articlePath + "?action=delete",

historyPage = articlePath + "?action=history",

movePage = mw.config.get("wgArticlePath").replace("$1", "Special:MovePage/" + pageName),

purgePage = articlePath + "?action=purge",

isEditorModal = window.location.href.match(/veaction/);

if(isEditorModal) {

currentAction = "edit";

}

function addShortcut(key, callback, config) {

var inputs = $("input, textarea, [contenteditable]");

var inFocus = $(inputs).is(":focus");

if(inFocus) {

console.log("Do nothing");

return false;

} else if(e.key == key) {

config.appliesTo.forEach(function(action) {

if(currentAction == action) {

callback;

}

});

return false;

}

}

function goTo(page) {

window.location.href = page;

}

addShortcut("e", function {

goTo(editPage);

}, {

appliesTo: ["view", "history", "delete"]

});

addShortcut("g" && "h", function {

goTo(historyPage);

}, {

appliesTo: ["view", "delete"]

});

addShortcut("d", function {

goTo(deletePage);

}, {

appliesTo: ["view", "history"]

});

addShortcut("m", function {

goTo(movePage);

}, {

appliesTo: ["view", "history", "delete"]

});

addShortcut("p", function {

goTo(purgePage);

}, {

appliesTo: ["view", "history"]

});

});