by Ange Tuteur May 7th 2015, 10:23 am
Sure, you could switch the target element to something else, such as <STRONG> or <SPAN>, and compare their textual content to your object's keys. Just change the user IDs, to the user's original username.
- Code:
$(function() {
var users = {
'u1' : '<span style="color:#00b554;text-shadow: 0px 2px 6px #6FB7E3">NightOwl</span>',
'u2' : '<span style="color:#000000;text-shadow: 0px 2px 6px #f756b7">エクリプスダルクス</span>',
'u5' : '<span style="color:#000000;text-shadow: 0px 0px 6px #FFFFFF">Shiny Checkinder</span>',
'u9' : '<span style="color:#2eafff;text-shadow: 0px 2px 6px #6FB7E3">Layre</span>',
'u12' : '<span style="color:#e19ef7;text-shadow: 0px 2px 6px #d3f513"> NintendoDan64</span>',
'u17' : '<span style="color:#49c7c9;text-shadow: 0px 2px 6px #6FB7E3">RockManGage</span> ',
'u20' : '<span style="color:#b649c9;text-shadow: 0px 2px 6px #6FB7E3">アシュ</span>',
'u21' : '<span style="color:#8246e3;text-shadow: 0px 2px 6px #6FB7E3">TheBooman</span>',
'u42' : '<span style="color:#ff2e2e;text-shadow: 0px 2px 6px #6FB7E3">Danny.D.Luffy</span>',
'u81' : '<span style="color:#0f97d6;text-shadow: 0px 2px 6px #FFFFFF">DragonDance2x</span>',
'u163' : '<span style="color:#40f74f;text-shadow: 0px 2px 6px #6FB7E3">STONERTRAINER420</span>',
'u173' : '<span style="color:#ed9315">Babnelo</span>',
'u182' : '<span style="color:##d4c41a;text-shadow: 0px 2px 6px #FFFFFF">TooCool4u</span>',
'u186' : '<span style="color:#009aed;text-shadow: 0px 2px 6px #6FB7E3">Suwako</span>',
'u204' : '<span style="color:#009aed;text-shadow: 0px 2px 6px #6FB7E3">masterdoctorten</span>'
},
a = document.getElementsByTagName('STRONG'), i = 0, j = a.length, k;
for (; i<j; i++) {
for (k in users) {
if ($(a[i]).text().toLowerCase() == k.toLowerCase()) {
a[i].innerHTML = users[k];
break;
}
}
}
});
Also, in the future, make sure that the last pair in an object
does not have a comma at the end. Today's browsers usually correct this, but some older browsers will throw an error, therefore halting the execution of other scripts in the same file.
It's a small detail, but it can cause problems if you overlook it.