Jump to content

User:Qwerfjkl/scripts/encode.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Qwerfjkl (talk | contribs) at 15:56, 27 December 2021 (Use prompt, easier to copy & paste). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// Make sure the utilities module is loaded (will only load if not already)
mw.loader.using( 'mediawiki.util', function () {

    // Wait for the page to be parsed
    $( document ).ready( function () { 

        var link = mw.util.addPortletLink( 'p-tb', '#', 'Encode', 'tb-encode', 'Encode character(s)'); 
        $( link ).click( function ( event ) {
            event.preventDefault();
            encodeHTML();

        } );
    } );
} );
function encodeHTML() {
	rawStr = prompt( "What do you want to encode?");
	var encodedStr = rawStr.replace(/[\u00A0-\u9999<>\&]/g, function(i) {
		return '&#'+i.charCodeAt(0)+';';
	});
	prompt( "The encoded string is: ", encodedStr);
}