User:AlanM1/scripts/CharHexDump.js

// //	Dumps current selection as hex values //	by User:AlanM1 v20141021a //

function CharHexDump($) { $(mw.util.addPortletLink('p-tb', '#', 'CharHexDump', 'CharHexDump', 'CharHexDump')).click(		function {			var n = 0;			var msg = '  n: 0 1  2 3  4 5  6 7  8 9  a b  c d  e f  Characters';			var msg2 = "";			$(window.getSelection.toString.split('')).each( function(index, item) { if (index % 8 == 0) { if (index > 0) { msg += ' ' + msg2; }						msg += '\n' + ('000' + ((index / 8).toString(16))).slice(-3) + 'n:'; msg2 = ''; }					n = item.charCodeAt(0); msg += ' ' + ('0000' + (n.toString(16))).slice(-4); if (n <= 31 || n == 38) { msg2 += '?'; } else { msg2 += item; }				}			)			msg += '                                         '					.substr(0, 6 * (5 * (8 - msg2.length) + 1)) + msg2 + '\n';			$('#chd-text').html(msg);			console.log($('#chd-text').html);			$('#chd-div').show;		}	)

$btn = $(' ') .attr({			id: 'chd-btnok',			style: 'position:absolute; top: 0; right: 0;'		}) .click(function{			$('#chd-div').hide;		}); $btn.append('X'); $txt = $(' ') .attr({			id: 'chd-text',			rows: 16,			cols: 55,			style: 'font-family:monospace'		}) .append($(' '));

$out = $(' ') .attr('id', 'chd-div') .attr('style', 'display:none; font-family:monospace; width:38em; height:21em; background-color:white; position:absolute; top:9.5em; left:13em; border: 1px solid black; padding: 1.6em 0.5em 0.5em 0.5em;') .append($btn) .append($txt) .append($(' '));

$(document.body).append($out); }

mw.loader.using(	'mediawiki.util',	function{		$(document).ready(CharHexDump);	} );

// 20141018a	Initial release with alert dialog and proportional font // 20141019a	Separate dialog with monospace font