Last.fm - Real Names delete lock Revision 653137353662 (Fri Apr 30 2010 at 15:18) - Diff Link to this snippet: https://friendpaste.com/5I4gCia8xh1fOH1oQ7c5JQ Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677// ==UserScript==// @name Last.fm - Real Names// @namespace none// @include http://www.last.fm*// @include http://www.lastfm.*// @include http://cn.last.fm*// ==/UserScript==function trim(str) { return str.replace(/^\s+/, '').replace(/\s+$/, '');}function getRealName(nick, elem, sliceBy, addRealName) { GM_xmlhttpRequest({ method: 'GET', url: 'http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user='+nick+'&api_key=b25b959554ed76058ac220b7b2e0a026', headers: { 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey/0.3', 'Accept': 'text/xml' }, onload: function(response) { if (!response.responseXML) { var xml = (new DOMParser()).parseFromString(response.responseText, 'text/xml'); } else { var xml = response.responseXML; } var realName = xml.getElementsByTagName('realname')[0].firstChild.nodeValue; if (realName) { if (addRealName == true) { var newText = realName.slice(0,sliceBy)+' ('+nick+')'; } else { var newText = realName.slice(0,sliceBy); } var replacedText = new RegExp(nick, 'gi'); if (!elem.hasAttribute('realNameAdded')) { elem.innerHTML = elem.innerHTML.replace(replacedText, newText); elem.setAttribute('realNameAdded', true); } } } });}function changeName(topElem, sliceBy, addRealName) { var re = /^http:\/\/(.*\.|)(last\.fm|lastfm\.[^\/]+)\/user\/([^\?#]*)$/i; var elems = topElem.getElementsByTagName('a'); for (var i = 0; i < elems.length; i++) { var elem = elems[i]; if (!elem.hasAttribute('realNameAdded')) { if (m = re.exec(elem.href)) { parts = m[3].split('/'); if (!parts[1]) { getRealName(parts[0], elem, sliceBy, addRealName); } } } }}var profileLinks = document.getElementById('profileLinks');if (profileLinks) changeName(profileLinks, 26, false); var aboutMe = document.getElementById('aboutMe');if (aboutMe) changeName(aboutMe, 30, false);var shoutList = document.getElementById('shoutList');if (shoutList) changeName(shoutList, 40, true);var recentDiscussions = document.getElementById('recentDiscussions');if (recentDiscussions) changeName(recentDiscussions, 60, true);changeName(document.body, 20, false);document.addEventListener('DOMNodeInserted', function(ev){ changeName(ev.originalTarget, 15, true); }, true);