Jump to content

User:Jeeputer/InternationalRefRenamer.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.
//This is a fork of [[User:Nardog/RefRenamer]] which suppose to support internationalization
//For more information see https://en.wikipedia.org/wiki/Special:Permalink/1140828312#i18n

mw.config.get('wgNamespaceNumber') % 2 === 0 &&
mw.config.get('wgArticleId') &&
mw.config.get('wgPageContentModel') === 'wikitext' &&
$.when($.ready, mw.loader.using('mediawiki.util')).then(function refRenamer() {
	if (!document.getElementById('p-tb')) return;
	
	if (mw.config.get('wgUserName') !== 'Jeeputer') return; // Currently testing
	
	let clicked;
	let lang = mw.config.get('wgContentLanguage');
	let i18n;
	$.getJSON('/w/index.php', {
	    action: 'raw',
	    ctype: 'application/json',
	    title: 'User:Jeeputer/InternationalRefRenamer.js/i18n.json'
	}).then(function(data) {
	    i18n = data[lang] || data['en']; // fall back to En if lang data missing
	    window.RefRenameri18n = i18n;
    	mw.util.addPortletLink('p-tb', '#', i18n['tool-name'], 't-refrenamer').firstElementChild.addEventListener('click', e => {
			e.preventDefault();
			if (clicked) {
				if (window.refRenamer) window.refRenamer();
				return;
			}
			clicked = true;
			mw.notify(i18n['tool-loading'], {
				autoHideSeconds: 'long',
				tag: 'refrenamer'
			});
			mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Jeeputer/InternationalRefRenamer-core.js&action=raw&ctype=text/javascript');
		});
	});
});