User:Erutuon/scripts/langCatRedirect.js

//

// Redirects you from Category: to Category: ; // for instance, to.

if (mw.config.get('wgNamespaceNumber') === 14 && mw.config.get('wgAction') == 'view' && /^[a-z]{2,3}(?:-[a-z]{2,3})*$/.test(mw.config.get('wgTitle'))) { $.getScript("//en.wiktionary.org/w/index.php?title=User:Erutuon/scripts/apiWrapper.js&action=raw") .done(function {		'use strict';		var title = mw.config.get('wgTitle');		var luaScript = 'mw.text.jsonEncode(require "Module:languages".getByCode("' + title + '"):getCategoryName)';		function handleLanguageData(languageDataJSON) {			var categoryName = JSON.parse(languageDataJSON);			if (categoryName)				location.href = mw.config.get('wgArticlePath').replace('$1', 'Category:' + categoryName);			else				mw.notify(mw.config.get('wgTitle') + " is not a valid language code.");		}		apiWrapper.callLua(luaScript, handleLanguageData);	}) .fail(function {		mw.log("fail");	}); }

//