TWStats map from rankings

Discussion in 'Scripts & Independent Tools' started by servy, Aug 28, 2008.

Share This Page

  1. servy

    servy All Over the Board

    Joined:
    Mar 7, 2007
    Messages:
    12,944
    Likes Received:
    1
    The idea behind this script is to go to any page on the rankings and make a twstats map of the first 10 tribes/players on that page. It works for the basic tribe/player rankings as well as for the continent or OD rankings.

    It took a bit of fussing to try to find the 10 best colors. I'm open to sugestions if you'd like the colors changed but in most cases you'll probably have to manually change the map if the colors don't work rather than changing the code.

    without whitespace:
    Code:
    javascript:var%20doc=document;if(window.frames.length>0)doc=window.main.document;url=doc.URL;link='http://twstats.com/'+getWorld(url)+'/index.php?page=map&centrex=500&centrey=500';link+='&zoom=100&grid=1&nocache=1&fill=000000';function%20getID(url){var%20start=url.indexOf("id=")+3;var%20end=url.indexOf('%26',start);var%20id;if(end>0)id=url.substring(start,end);else{id=url.substring(start);}return%20id;}function%20getWorld(url){start=url.indexOf("en");return%20url.substring(start,url.indexOf('.',start));}if(url.indexOf('screen=ranking')==-1){alert('This%20script%20needs%20to%20be%20called%20from%20one%20of%20the%20rankings%20pages');}else{table="";ths=doc.getElementsByTagName('th');for(i=0;i<ths.length&&table=="";i++){if(ths[i].innerHTML=='Rank'){table=ths[i].parentNode.parentNode;}}type='';if(url.indexOf('mode=player')!=-1||url.indexOf('mode=con_player')!=-1||url.indexOf('mode=kill_player')!=-1)type='player';else%20if(url.indexOf('mode=ally')!=-1||url.indexOf('mode=con_ally')!=-1||url.indexOf('mode=kill_ally')!=-1)type='tribe';rows=table.rows;for(i=1;i<11;i++){tLink=rows[i].cells[1].childNodes[0].href;link+='&'+type+'_'+(i-1)+'_id='+getID(tLink);}link+='&'+type+'_0_colour=00FF00';link+='&'+type+'_1_colour=00FFFF';link+='&'+type+'_2_colour=FFFFFF';link+='&'+type+'_3_colour=FFFF00';link+='&'+type+'_4_colour=FF8040';link+='&'+type+'_5_colour=FF0080';link+='&'+type+'_6_colour=C0C0C0';link+='&'+type+'_7_colour=FF0000';link+='&'+type+'_8_colour=808080';link+='&'+type+'_9_colour=FF00FF';window.open(link);}end();
    with whitespace:
    PHP:
    javascript:
    var 
    doc=document;
    if(
    window.frames.length>0)
        
    doc=window.main.document;
    url=doc.URL;
    link='http://twstats.com/'+getWorld(url)+'/index.php?page=map&centrex=500&centrey=500';
    link+='&zoom=100&grid=1&nocache=1&fill=000000';
    function 
    getID(url){
        var 
    start=url.indexOf("id=")+3;
        var 
    end=url.indexOf('%26',start);
        var 
    id;
        if(
    end>0)
            
    id=url.substring(start,end);
        else{
            
    id=url.substring(start);
        }
        return 
    id;
    }
    function 
    getWorld(url){
        
    start=url.indexOf("en");
        return 
    url.substring(start,url.indexOf('.',start));
    }
    if(
    url.indexOf('screen=ranking')==-1){
        
    alert('This script needs to be called from one of the rankings pages');
    }
    else{
        
    table="";
        
    ths=doc.getElementsByTagName('th');
        for(
    i=0;i<ths.length&&table=="";i++){
            if(
    ths[i].innerHTML=='Rank'){
                
    table=ths[i].parentNode.parentNode;
            }
        }
        
    type='';
        if(
    url.indexOf('mode=player')!=-1||url.indexOf('mode=con_player')!=-1||url.indexOf('mode=kill_player')!=-1)
            
    type='player';
        else if(
    url.indexOf('mode=ally')!=-1||url.indexOf('mode=con_ally')!=-1||url.indexOf('mode=kill_ally')!=-1)
            
    type='tribe';
        
        
    rows=table.rows;
        for(
    i=1;i<11;i++){
            
    tLink=rows[i].cells[1].childNodes[0].href;
            
    link+='&'+type+'_'+(i-1)+'_id='+getID(tLink);
        }
        
    link+='&'+type+'_0_colour=00FF00';
        
    link+='&'+type+'_1_colour=00FFFF';
        
    link+='&'+type+'_2_colour=FFFFFF';
        
    link+='&'+type+'_3_colour=FFFF00';
        
    link+='&'+type+'_4_colour=FF8040';
        
    link+='&'+type+'_5_colour=FF0080';
        
    link+='&'+type+'_6_colour=C0C0C0';
        
    link+='&'+type+'_7_colour=FF0000';
        
    link+='&'+type+'_8_colour=808080';
        
    link+='&'+type+'_9_colour=FF00FF';
        
        
    window.open(link);
    }
    end();
    This one will work from a tribe's members page:
    Code:
    javascript:var%20doc=document;if(window.frames.length>0)doc=window.main.document;var%20url=doc.URL;var%20link='http://twstats.com/'+getWorld(url)+'/index.php?page=map&centrex=500&centrey=500';link+='&zoom=100&grid=1&nocache=1&fill=000000';function%20getID(aUrl){var%20start=aUrl.indexOf("id=")+3;var%20end=aUrl.indexOf('%26',start);var%20id;if(end>0)id=aUrl.substring(start,end);else{id=aUrl.substring(start);}return%20id;}function%20getWorld(){start=url.indexOf("en");return%20url.substring(start,url.indexOf('.',start));}if(url.indexOf('screen=info_member')==-1){alert('This%20script%20needs%20to%20be%20called%20from%20a%20tribe\'s%20members%20page');}else{table="";ths=doc.getElementsByTagName('th');for(i=0;i<ths.length&&table=="";i++){if(ths[i].innerHTML=='Rank'){table=ths[i].parentNode.parentNode;}}rows=table.rows;for(i=1;i<Math.min(11,rows.length);i++){tLink=rows[i].cells[0].getElementsByTagName('a')[0].href;link+='&player_'+(i-1)+'_id='+getID(tLink);}link+='&player_0_colour=00FF00';link+='&player_1_colour=00FFFF';link+='&player_2_colour=FFFFFF';link+='&player_3_colour=FFFF00';link+='&player_4_colour=FF8040';link+='&player_5_colour=FF0080';link+='&player_6_colour=C0C0C0';link+='&player_7_colour=FF0000';link+='&player_8_colour=808080';link+='&player_9_colour=FF00FF';window.open(link);}end();
     
    Last edited: Aug 31, 2008
  2. servy

    servy All Over the Board

    Joined:
    Mar 7, 2007
    Messages:
    12,944
    Likes Received:
    1
    I have a feeling some of the mapmakers are going to like not having to put so much effort into getting the raw data for their maps. Either that or it'll give enough people easy access to the data so they won't need to use such maps as often.
     
  3. allyboo

    allyboo <img src="http://web.extern.innogames.de/morthy/lo

    Joined:
    Aug 5, 2007
    Messages:
    2,159
    Likes Received:
    0
    This is a yummy tool. I think this will encourage more graphical maps perhaps, because the biggest pain in doing these things is getting the initial image to work from, and you've just fixed that. Many thanks :)
     
  4. cecala

    cecala Contributing Poster

    Joined:
    Jan 23, 2008
    Messages:
    2,964
    Likes Received:
    0
    thx servy u work fast... =)

    anyway is there a fast way to change the amount of top tribes u want to be included??

    like easily change it from top 10 to 15 or 20?
     
    Last edited: Aug 30, 2008
  5. Spoona-x-

    Spoona-x- Contributing Poster

    Joined:
    Feb 27, 2008
    Messages:
    1,409
    Likes Received:
    0
    Thanks alot servy :)

    This is just what i need to speed up my map making :)
     
  6. stabfight

    stabfight Non-stop Poster

    Joined:
    Nov 16, 2007
    Messages:
    196
    Likes Received:
    0
    another cool script servy!

    hey, is there anyway to modify this script to run from a tribe's members page?

    . . . although i guess you would have to enter center and zoom info manually to make it more tribe specific. . . no, i still think its a cool idea. . . possible?
     
  7. servy

    servy All Over the Board

    Joined:
    Mar 7, 2007
    Messages:
    12,944
    Likes Received:
    1
    It wouldn't be that hard to include the tribes, but the big issue is that there aren't that many more colors and most of the remaining colors don't contrast well with the others. If you didn't care that they were all the same color then the change would only take a minute or two.
     
  8. servy

    servy All Over the Board

    Joined:
    Mar 7, 2007
    Messages:
    12,944
    Likes Received:
    1
    Should be possible. I'll look into it tomorrow.
     
  9. stabfight

    stabfight Non-stop Poster

    Joined:
    Nov 16, 2007
    Messages:
    196
    Likes Received:
    0
  10. Odoakar

    Odoakar Contributing Poster

    Joined:
    Mar 21, 2008
    Messages:
    1,073
    Likes Received:
    1
    Another map maker thankful for this nice script.


    The part 'link+='&zoom=100&grid=1&nocache=1&fill=000000'; ' is the one where you can change the zoom, right?

    Another question...the color used for each tribe must be same as the colors used on TWMaps? I could easily take from photoshop codes for 20 different colors that don't look too same. As cecala, I'd like to see this for more than 10 tribes
     
  11. servy

    servy All Over the Board

    Joined:
    Mar 7, 2007
    Messages:
    12,944
    Likes Received:
    1
    If you had any color that isn't one of the options for the twstats map it would default it to grey.
     
  12. Odoakar

    Odoakar Contributing Poster

    Joined:
    Mar 21, 2008
    Messages:
    1,073
    Likes Received:
    1
    So here's a pretty lame question, why doesn't TWMaps get some improvement where one could choose more colors? Something like http://en14.twmaps.org/. TWMaps have darker green, and better grid lines so I prefer to use those maps as base for later editing
     
  13. servy

    servy All Over the Board

    Joined:
    Mar 7, 2007
    Messages:
    12,944
    Likes Received:
    1
    that site has no way of saving the maps that you make nor crating them via a get request, as far as I can tell, making that an impossible option.
     
  14. daisho

    daisho Contributing Poster

    Joined:
    May 1, 2007
    Messages:
    1,260
    Likes Received:
    0
    I wasn't sure based on your post if you wanted suggestions on the colors but I suggest changing light grey to dark blue since light grey is similar to white.

    Also light purple to dark purple since pink and light purple are hard tell apart.

    This is not a complaint servy; thanks so much this will save me so much time.
     
  15. servy

    servy All Over the Board

    Joined:
    Mar 7, 2007
    Messages:
    12,944
    Likes Received:
    1
    I originally had dark blue in there but it was extremely hard to tell apart from the black background. Same with the dark purple.
     
  16. daisho

    daisho Contributing Poster

    Joined:
    May 1, 2007
    Messages:
    1,260
    Likes Received:
    0
    Oh right, I changed the background and forgot.
     
  17. John Lenin

    John Lenin Non-stop Poster

    Joined:
    Feb 23, 2008
    Messages:
    418
    Likes Received:
    0
    Well done.

    I would suggest replacing light grey with light blue and light purple with dark purple or burgundy.
     
  18. stabfight

    stabfight Non-stop Poster

    Joined:
    Nov 16, 2007
    Messages:
    196
    Likes Received:
    0
    *pssst*

     
  19. servy

    servy All Over the Board

    Joined:
    Mar 7, 2007
    Messages:
    12,944
    Likes Received:
    1
    I just moved in to college today, I'll look into it later.
     
  20. servy

    servy All Over the Board

    Joined:
    Mar 7, 2007
    Messages:
    12,944
    Likes Received:
    1
    Just added that to the OP.

    /me demands huggles.