User:SD0001/np-shortcuts.js
// Make n and p keyboard shortcut to go the next/previous set of results while viewing article histories,
// search results, user contributions or logs, and to go to the next/previous diff while viewing a diff.
$.ready.then(function() {
document.addEventListener('keyup', function(e) {
var activeEl = document.activeElement.tagName;
if (activeEl === 'TEXTAREA' || activeEl === 'INPUT') {
return;
}
if (e.key === 'n') {
var nextLink = document.querySelector('a.mw-nextlink') || document.getElementById('differences-nextlink');
if (nextLink) {
location.href = nextLink.href;
}
} else if (e.key === 'p') {
var prevLink = document.querySelector('a.mw-prevlink') || document.getElementById('differences-prevlink');
if (prevLink) {
location.href = prevLink.href;
}
}
});
});