MediaWiki:Common.js: Difference between revisions

From Coral Island Wiki
Jump to navigation Jump to search
No edit summary
(add exceptions to keybinds)
Line 19: Line 19:
$(document).on('keydown', function(e) {
$(document).on('keydown', function(e) {
var key = e.key.toLocaleLowerCase();
var key = e.key.toLocaleLowerCase();
if (actions[key]) {
if (
actions[key] &&
!(e.target && ['INPUT', 'TEXTAREA'].includes(e.target.nodeName)) &&
config.wgCanonicalSpecialPageName===false
) {
newUrl.searchParams.set('action', actions[key]);
newUrl.searchParams.set('action', actions[key]);
document.location.href=newUrl.href;
document.location.href=newUrl.href;

Revision as of 04:21, 10 July 2024

var config = mw.config.values;

// Load personal JS if any
importScript('User:'+config.wgUserName+'/common.js');

// Load site JS
importScript('MediaWiki:BetterUpload.js');

// Add navigational keybinds
mw.hook('wikipage.content').add(function(){
	var actions = {
		e: 'edit',
		h: 'history',
		m: 'move',
		d: 'delete',
	};
	if (config.wgAction=='view') {
		var newUrl = new URL(document.location.href);
		$(document).on('keydown', function(e) {
			var key = e.key.toLocaleLowerCase();
			if (
				actions[key] &&
				!(e.target && ['INPUT', 'TEXTAREA'].includes(e.target.nodeName)) &&
				config.wgCanonicalSpecialPageName===false
			) {
				newUrl.searchParams.set('action', actions[key]);
				document.location.href=newUrl.href;
			}
		});
	}
});