Jump to content

User:InvalidOS/unicodeRedirect.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.
$(document).ready( function () {

var config = {};

config.mw = mw.config.get( [
	'wgPageName'
] );



if (config.mw.wgPageName.length == 1)
{
	var hex = config.mw.wgPageName.charCodeAt(0).toString(16);
	var result;
	if (hex.length <= 4)
	{
		result = "U%2B" + ("0000".substring(0, 4 - hex.length) + hex).toUpperCase();
	}
	else
	{
		result = "U%2B" + hex.toUpperCase();
	}
	mw.loader.using(['mediawiki.util']), mw.util.addPortletLink(
		'p-views',
		'index.php?title=' + result + '&action=view&redirect=no',
		'Codepoint',
		'ca-unicode',
		'Corresponding Codepoint Page',
		'-',
		document.getElementById('ca-history')
	);
}

if (config.mw.wgPageName.startsWith("U+") === true)
{
	var result2;
	var pass = true;
	try
	{
		result2 = String.fromCharCode(parseInt(config.mw.wgPageName.substring(2, config.mw.wgPageName.length), 16));
	}
	catch (err)
	{
		pass = false;
	}
	
	if (pass === true)
	{
		mw.loader.using(['mediawiki.util']), mw.util.addPortletLink(
			'p-views',
			'index.php?title=' + result2 + '&action=view&redirect=no',
			'Character',
			'ca-unicode',
			'Corresponding Character Page',
			'-',
			document.getElementById('ca-history')
		);
	}
}

} );