The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Script to change several usernames color?

+2
Ange Tuteur
Sir. Mayo
6 posters

Go down

Solved Script to change several usernames color?

Post by Sir. Mayo Wed Apr 29 2015, 16:48

Hello,


I was wondering if there is any way i could have one script to change the color of several different user-names, and have each one be a different color.

I know i can change one at a time with a script like this:
Code:
$(document).ready(function(){
$('a:contains("STONERTRAINER420")').replaceWith('
<a href="/u163" style="text-decoration : none;"><span style="color:#ff0000;"><b>STONERTRAINER420</b></span></a>
');
});

Now is there any way i can add more names to it that get replaced or would i need to have a separate script for each name, I was trying to change about 10-15 names and they each where going to be a different color. Any help would be great. Thanks guys.


Last edited by Sir. Mayo on Thu May 07 2015, 13:52; edited 2 times in total
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 978
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Ange Tuteur Wed Apr 29 2015, 23:52

Hi @Sir. Mayo,

Personally, I'd recommend creating an object that contains your members IDs + the HTML for their custom name. Here's a quick example I wrote up :
Code:
$(function() {
  var users = {
    'u1' : '<span style="color:red">MY</span> <span style="color:blue">NAME</span>',
    'u2' : '<span style="color:purple">ANOTHER</span> <span style="color:pink">NAME</span>'
  },
  a = document.getElementsByTagName('A'), i = 0, j = a.length, k;
 
  for (; i<j; i++) for (k in users) $(a[i]).attr('href') == ('/' + k).toLowerCase() && (a[i].innerHTML = users[k]);
});

You'll see the object at the top of the script named users. Inside it you'll see id:html pairs :

id : The ID of the user you want to modify
html : The html used as the replacement

You can add as much as you want, so long as you separate each pair by a comma. Wink
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Sir. Mayo Wed Apr 29 2015, 23:56

Thanks. It is solved but could we leave it open for a little in case i have trouble with the code?
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 978
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Ange Tuteur Wed Apr 29 2015, 23:59

Sure, just let me know if you have any questions, or you're completely sure that you wont have any trouble. Smile
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Sir. Mayo Fri May 01 2015, 01:31

Code:
$(function() {
  var users = {
    'u1' : '<span style="color:red">MY</span> <span style="color:blue">NAME</span>',
    'u2' : '<span style="color:purple">ANOTHER</span> <span style="color:pink">NAME</span>'
  },
  a = document.getElementsByTagName('A'), i = 0, j = a.length, k;
 
  for (; i<j; i++) for (k in users) $(a[i]).attr('href') == ('/' + k).toLowerCase() && (a[i].innerHTML = users[k]);
});




@ange tuteur so the code you gave me is not coloring the names on the  forum, or even replacing the names with the colored ones. Is there something wrong with the code. The last one i had changed each name to the color i wanted. any other help would be great.


so it was the 404 error that was not allowing the code to show, once i refreshed and accualty connected it worked! This can be archived now.
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 978
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Ange Tuteur Fri May 01 2015, 02:20

Okay, you're welcome ^^

Topic archived

Have a nice day and see you. Smile
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Derri Wed May 06 2015, 17:46

Topic reopened on author's request
Derri
Derri
Helper
Helper

Male Posts : 8711
Reputation : 638
Language : English & Basic French
Location : Scotland, United Kingdom

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Sir. Mayo Wed May 06 2015, 17:50

Hello,

@Ange Tuteur So the code you provided works great on the forum but when we view a users profile its reverts back to the default color. Maybe i did something wrong?
Here is the edited code that i add my stuff too

Code:
$(function() {
  var users = {
    'u1' : '<span style="color:#00b554" "  text-shadow: 0px 2px 6px #6FB7E3">NightOwl',

    '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('A'), i = 0, j = a.length, k;
 
  for (; i<j; i++) for (k in users) $(a[i]).attr('href') == ('/' + k).toLowerCase() && (a[i].innerHTML = users[k]);
});

Any help would be great.

EDIT: It also appears that their avatar is not showing up in the member list now. ?
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 978
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by SLGray Wed May 06 2015, 21:26

Do you have it set for all pages?


Script to change several usernames color?  Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51572
Reputation : 3525
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Sir. Mayo Wed May 06 2015, 21:27

Yes, sir. Could that be it. We wanted it to change the names on the entire forum.
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 978
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by SLGray Wed May 06 2015, 21:28

Well then it needs to be set for all pages.

You have a comma in the last one in your code.

Code:
'u204' : '<span style="color:#009aed" "text-shadow: 0px 2px 6px #6FB7E3">masterdoctorten</span> ',


Script to change several usernames color?  Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51572
Reputation : 3525
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Sir. Mayo Wed May 06 2015, 21:37

Thanks for the reply SlGary but i removed the comma and it still does not display the avatars.

The only issue i can think of is that its changing the image in the member list because of the alt tag for the said image. If that makes sense?
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 978
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by SLGray Wed May 06 2015, 21:49

Could you let guests see the memberlist?


Script to change several usernames color?  Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51572
Reputation : 3525
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Sir. Mayo Wed May 06 2015, 21:50

They are already set up to see the member list.
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 978
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by SLGray Wed May 06 2015, 21:53

Is this your forum - http://sir-mayo.forumotion.com/ ?

I do not see a memberlist button.


Script to change several usernames color?  Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51572
Reputation : 3525
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Sir. Mayo Wed May 06 2015, 21:53

No sorry i should have said the URL. the forum in question is

http://pokemoncircle.pokemonrpg.org
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 978
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by SLGray Wed May 06 2015, 21:56

I believe you are correct that this code is overriding the avatars.


Script to change several usernames color?  Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51572
Reputation : 3525
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Sir. Mayo Wed May 06 2015, 22:03

Yes.
When i sign in i see this and when i use a guest account i see the same thing as well:
Script to change several usernames color?  Screenshot_from_2015_05_06_14_57_26
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 978
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Ange Tuteur Thu May 07 2015, 02:28

Change your script to this :
Code:
$(function() {
  var users = {
    'u1' : '<span style="color:#00b554;text-shadow: 0px 2px 6px #6FB7E3">NightOwl',

    '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('A'), i = 0, j = a.length, k;
 
  for (; i<j; i++) for (k in users) if ($(a[i]).attr('href') == ('/' + k).toLowerCase() && !/avatar/.test(a[i].parentNode.className)) a[i].innerHTML = users[k];
});

As for it not working on the profile name. It's only programmed to work with anchor elements ( <A> ), the script iterates over each one and checks if the HREF attribute contains the user's key ( e.g. u1, u2, u3.. ). If it does, it'll replace the innerHTML content with what you specified as that key's value.

In short, if the name isn't an anchor with that user's ID, the custom name wont display.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Sir. Mayo Thu May 07 2015, 03:01

Thanks. Is there any way i can get them to show up in the profile?
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 978
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Ange Tuteur Thu May 07 2015, 11:23

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. grrr!!!!!
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Sir. Mayo Thu May 07 2015, 13:52

Thanks Solved Again.
Sir. Mayo
Sir. Mayo
Forumember

Male Posts : 978
Reputation : 90
Language : English, Some french.
Location : you can also reach me on snoonet's irc server. I idle in #Techsupport Username is Vault108

http://sir-mayo.forumotion.com/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Ange Tuteur Thu May 07 2015, 14:18

I'll leave this open for now, in case there's anymore problems that you encounter. Smile
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Pizza Boi Sat May 09 2015, 06:31

Hi Very Happy

@Ange Tuteur : Is it possible to have this code intact even in chat box? Like the color to remain even when you log in chat box since it disappears once we do?

Regards,
Pizza Boi
Pizza Boi
Pizza Boi
Hyperactive

Male Posts : 2016
Reputation : 160
Language : French
Location : Pizza Hut!

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Ape Wed May 13 2015, 16:11

@Pizza Boi please remember that when Tagging
Ange Tuteur you must use the following code
Code:
@"Ange Tuteur"
to tag him as the way you have tagged now will not tag the right person.

Much thanks.

APE


Script to change several usernames color?  Left1212Script to change several usernames color?  Center11Script to change several usernames color?  Right112
Script to change several usernames color?  Ape_b110
Script to change several usernames color?  Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19452
Reputation : 2011
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Solved Re: Script to change several usernames color?

Post by Ape Sun May 17 2015, 18:06

as this is marked as solved by the thread starter i will lock it any problems please pm me this link

APE
Topic solved and archived


Script to change several usernames color?  Left1212Script to change several usernames color?  Center11Script to change several usernames color?  Right112
Script to change several usernames color?  Ape_b110
Script to change several usernames color?  Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19452
Reputation : 2011
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum