Getting the current user’s alias

For a project I’m working on, I needed to know what the logged in user’s account alias was.  Looking around I found examples that would make a ajax call out to the profile page and parse the results.  This seemed like overkill for what I wanted and on a whim I decided to view-source on the Search Center results page and search for my user name… Sure enough, there it is:

accountname

The hidden QLogEnv inputs are used to click event tracking but this is good enough for me.   Here’s the JQuery I used to pull it out:

function pullAlias() {
// Pull the alias or return null
var p = /<un>[a-zA-Z]+\\([^<]+)/;
var l = $('input').map(function(index) {
if (this.name.startsWith("QLogEnv") && (this.value.indexOf("<un>") != -1)) {
var r = p.exec(this.value);
if (r) {
return r[1]
}
}
})
if (!l) { return } // no alias found?
return l[0]
}