Convert JavaScript Escaped Characters to HTML/XML Entities

11. January 2012 01:44 by Cameron in javascript  //  Tags: , , , , , ,   //   Comments

Recently, I needed a way to convert JavaScript escaped characters to HTML/XML entities for saving files in UTF-8 encoding without saving the special characters to disk. Luckily this was pretty easy. I used JavaScript's built-in function escape() to escape the input text and used regular expressions to find each escaped value and replace them in the input text with their new HTML/XML entity equivalent. For example, the text "Copyright Some Company ©" would escape to "Copyright%20Some%20Company%20%A9" using JavaScript's built-in function escape(). After converting the escaped characters to entities, the result would be "Copyright Some Company ©". When saved in a database and rendered as HTML to a webpage, it would display the original message "Copyright Some Company ©". Here's the code for anyone interested:

// convert escaped characters to html/xml entities
function normalizeText(text)
{
	// escape text for special characters
	var esc = escape(text);
	var simpleCharsRegex = /%[0-9A-Fa-f][0-9A-Fa-f]/g;
	var specialCharsRegex = /%u[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]/g;
	var simpleCharsMatch = esc.match(simpleCharsRegex);
	var specialCharsMatch = esc.match(specialCharsRegex);
	if(simpleCharsMatch!=null)
	{
		for(var i = 0; i < simpleCharsMatch.length; i++)
		{
			var temp = simpleCharsMatch[i];
			simpleCharsMatch[i] = simpleCharsMatch[i].replace(/%/, 'x') + ';';
			esc = esc.replace(temp, simpleCharsMatch[i]);
		}
	}
	if(specialCharsMatch!=null)
	{
		for(var i = 0; i < specialCharsMatch.length; i++)
		{
			var temp = specialCharsMatch[i];
			specialCharsMatch[i] = specialCharsMatch[i].replace(/%u/, 'x') + ';';
			esc = esc.replace(temp, specialCharsMatch[i]);
		}
	}
	return esc;
}

I understand there may be a more efficient way to do this, but this code does work in a pinch. Please let me know in the comments if you have any suggestions for improving this code.

Beginning Desktop Client for IGA

2. January 2012 18:45 by Cameron in PSN, Xbox Live  //  Tags: , , , , , , , , , , ,   //   Comments

After some time to think about the most secure method for processing achievements and trophies for an individual user using the user's account credentials, I've decided that using a desktop client rather than server side technology for collecting achievements and trophies is the best approach. Not only is it more secure, but it also reduces the load on my server by turning each user's computer into a node on the IGA network for processing small parts of achievements and trophy data as a whole. The combined data from each user will be uploaded to the IGA dedicated server for importing into the central database. Then data can be viewed from the web interface or smart phone applications.

The web interface and smart phone applications will merely serve as a way to interact with the data from the database rather than pulling data down from the various sources and taking up bandwidth. This is good for smart phone users as data charges can apply for checking for updates frequently.

I'm using a Qt, a cross platform GUI library, for designing the user interface so that the client may run on Windows, Mac OS X, and Linux out of the box. I will post some screen shots as they become available.

Latest updates on Xbox LIVE script

2. January 2012 13:28 by Cameron in Xbox Live  //  Tags: , , , , , , ,   //   Comments

I have recently added support for collecting data for an Xbox user's friend list to my Xbox LIVE script. Also, since my last blog update, I've changed all dates in the data to use epoch time stamps. I've attached an updated sample:

pcmantinker-xbox.xml (528.72 kb)

First version of PSN trophy collector finished

2. January 2012 13:17 by Cameron in PSN  //  Tags: , , , , , ,   //   Comments

Today I finished the first version of my PSN trophy collector. In this version, my script is able to pull down detailed information about a person's basic profile information and their full online game list with trophies. Note: the script only pulls games that play online and participate in trophies. Any games that don't have trophies are not scanned. For each game, a full list of trophies is collected showing the dates of each earned trophy. I've attached a sample of my PSN trophy data.

pcmantinker-ps3.xml (234.28 kb)

Month List

Tag cloud