Haven't even touched at code in a long time. But I tried making a little greasemonkey script a while back to give certain users titles of my choice. I thought it would be easy, just grab the name of the user, then insert some HTML code after it to mimic a title.
The code is messy, and yes I can see parts are very unreliable, but it's all I could think of.
[code]
var allTextareas, thisTextarea;
allTextareas = document.getElementsByTagName('font');
for (var i = 0; i < allTextareas.length; i++) {
thisTextarea = allTextareas[i];
if (thisTextarea.innerHTML == 'tim') {
var newElement = document.createElement('div');
newElement.innerHTML = '<br/><a href="http://www.dot.com">[1]</a>';
thisTextarea.insertBefore(newElement, thisTextarea.nextSibling);
}
if (thisTextarea.innerHTML == 'ted') {
var newElement = document.createElement('div');
newElement.innerHTML = '<br/><a href="http://www.tod.com">[1]</a>';
thisTextarea.insertBefore(newElement, thisTextarea.nextSibling);
}
}
[/code]
Here's a snippet of the HTML, slightly changed with formatting for better reading:
[code]
<div class="userinfo">
<div class="username">
<a class="Offline" href="member.php?u=000000">
<font color="red">ted</font>
</a>
</div>
<div class="usertitle"></div>
</div>
[/code]
Hoping some one could help make it a touch more reliable, such as mods have html tags like <b> in their name, or if there's another method to use other than looking in the <font> tag for user names.
On another note. I totally missed the Web Programming section. How new is that?
You could use if(thisTextarea.innerHTML.indexOf('tim') >= 0) to find a username.
Take this for a spin. I haven't tested it, but it should do the trick, in theory.
[code]
var allTextareas, thisTextarea;
allTextareas = document.getElementsByClassName('username');;
for (var i = 0; i < allTextareas.length; i++) {
thisTextarea = allTextareas[i];
if (thisTextarea.textContent == 'tim') {
thisTextarea.nextSibling.nextSibling.innerHTML = '<a href="http://www.dot.com">[1]</a>';
}
if (thisTextarea.innerHTML == 'ted') {
thisTextarea.nextSibling.nextSibling.innerHTML = '<a href="http://www.tod.com">[1]</a>';
}
}
[/code]
[QUOTE=Morphology53;18599765]Take this for a spin. I haven't tested it, but it should do the trick, in theory.
[code]
var allTextareas, thisTextarea;
allTextareas = document.getElementsByClassName('username');;
for (var i = 0; i < allTextareas.length; i++) {
thisTextarea = allTextareas[i];
if (thisTextarea.textContent == 'tim') {
thisTextarea.nextSibling.nextSibling.innerHTML = '<a href="http://www.dot.com">[1]</a>';
}
if (thisTextarea.innerHTML == 'ted') {
thisTextarea.nextSibling.nextSibling.innerHTML = '<a href="http://www.tod.com">[1]</a>';
}
}
[/code][/QUOTE]
Cheers. Works perfect. Well after the second if statement is fixed.
Thanks a lot.
[QUOTE=JSharpe;18600825][QUOTE=Morphology53;18599765]Take this for a spin. I haven't tested it, but it should do the trick, in theory.
[code]
var allTextareas, thisTextarea;
allTextareas = document.getElementsByClassName('username');;
for (var i = 0; i < allTextareas.length; i++) {
thisTextarea = allTextareas[i];
if (thisTextarea.textContent == 'tim') {
thisTextarea.nextSibling.nextSibling.innerHTML = '<a href="http://www.dot.com">[1]</a>';
}
if (thisTextarea.innerHTML == 'ted') {
thisTextarea.nextSibling.nextSibling.innerHTML = '<a href="http://www.tod.com">[1]</a>';
}
}
[/code][/QUOTE]
Cheers. Works perfect. Well after the second if statement is fixed.
Thanks a lot.[/QUOTE]
Aha, oops.
Sorry, you need to Log In to post a reply to this thread.