Jump to content

User:SD0001/np-shortcuts.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// 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;
	        }
	    }
	});
});