Script to change several usernames color?  Hitskin_logo Hitskin.com

This is a Hitskin.com skin preview
Install the skinReturn to the skin page

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.
+2
Ange Tuteur
Sir. Mayo
6 posters

    Script to change several usernames color?

    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

    Solved Script to change several usernames color?

    Post by Sir. Mayo April 29th 2015, 3:48 pm

    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 May 7th 2015, 12:52 pm; edited 2 times in total
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    Solved Re: Script to change several usernames color?

    Post by Ange Tuteur April 29th 2015, 10:52 pm

    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
    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

    Solved Re: Script to change several usernames color?

    Post by Sir. Mayo April 29th 2015, 10:56 pm

    Thanks. It is solved but could we leave it open for a little in case i have trouble with the code?
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    Solved Re: Script to change several usernames color?

    Post by Ange Tuteur April 29th 2015, 10:59 pm

    Sure, just let me know if you have any questions, or you're completely sure that you wont have any trouble. Smile
    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

    Solved Re: Script to change several usernames color?

    Post by Sir. Mayo May 1st 2015, 12:31 am

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


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

    Solved Re: Script to change several usernames color?

    Post by Ange Tuteur May 1st 2015, 1:20 am

    Okay, you're welcome ^^

    Topic archived

    Have a nice day and see you. Smile
    Derri
    Derri
    Helper
    Helper


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

    Solved Re: Script to change several usernames color?

    Post by Derri May 6th 2015, 4:46 pm

    Topic reopened on author's request
    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

    Solved Re: Script to change several usernames color?

    Post by Sir. Mayo May 6th 2015, 4:50 pm

    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. ?
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51554
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: Script to change several usernames color?

    Post by SLGray May 6th 2015, 8:26 pm

    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.
    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

    Solved Re: Script to change several usernames color?

    Post by Sir. Mayo May 6th 2015, 8:27 pm

    Yes, sir. Could that be it. We wanted it to change the names on the entire forum.
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51554
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: Script to change several usernames color?

    Post by SLGray May 6th 2015, 8:28 pm

    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.
    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

    Solved Re: Script to change several usernames color?

    Post by Sir. Mayo May 6th 2015, 8:37 pm

    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?
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51554
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: Script to change several usernames color?

    Post by SLGray May 6th 2015, 8:49 pm

    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.
    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

    Solved Re: Script to change several usernames color?

    Post by Sir. Mayo May 6th 2015, 8:50 pm

    They are already set up to see the member list.
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51554
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: Script to change several usernames color?

    Post by SLGray May 6th 2015, 8:53 pm

    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.
    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

    Solved Re: Script to change several usernames color?

    Post by Sir. Mayo May 6th 2015, 8:53 pm

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

    http://pokemoncircle.pokemonrpg.org
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51554
    Reputation : 3523
    Language : English
    Location : United States

    Solved Re: Script to change several usernames color?

    Post by SLGray May 6th 2015, 8:56 pm

    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.
    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

    Solved Re: Script to change several usernames color?

    Post by Sir. Mayo May 6th 2015, 9:03 pm

    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
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    Solved Re: Script to change several usernames color?

    Post by Ange Tuteur May 7th 2015, 1:28 am

    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.
    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

    Solved Re: Script to change several usernames color?

    Post by Sir. Mayo May 7th 2015, 2:01 am

    Thanks. Is there any way i can get them to show up in the profile?
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    Solved Re: Script to change several usernames color?

    Post 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. grrr!!!!!
    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

    Solved Re: Script to change several usernames color?

    Post by Sir. Mayo May 7th 2015, 12:52 pm

    Thanks Solved Again.
    Ange Tuteur
    Ange Tuteur
    Forumaster


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

    Solved Re: Script to change several usernames color?

    Post by Ange Tuteur May 7th 2015, 1:18 pm

    I'll leave this open for now, in case there's anymore problems that you encounter. Smile
    Pizza Boi
    Pizza Boi
    Hyperactive


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

    Solved Re: Script to change several usernames color?

    Post by Pizza Boi May 9th 2015, 5:31 am

    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
    Ape
    Ape
    Administrator
    Administrator


    Male Posts : 19432
    Reputation : 2010
    Language : fluent in dork / mumbojumbo & English haha

    Solved Re: Script to change several usernames color?

    Post by Ape May 13th 2015, 3:11 pm

    @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 : 19432
    Reputation : 2010
    Language : fluent in dork / mumbojumbo & English haha

    Solved Re: Script to change several usernames color?

    Post by Ape May 17th 2015, 5:06 pm

    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