hacker.org Forum Index
RegisterSearchFAQMemberlistUsergroupsLog in
JS Rank calculator

 
Reply to topic    hacker.org Forum Index » The Hacker's Server View previous topic
View next topic
JS Rank calculator
Author Message
Napoleon



Joined: 11 Dec 2010
Posts: 23
Location: Faroe Islands

Post JS Rank calculator Reply with quote
Well not to surprise everyone, but the "Rank" does not equal the row you're on, in the top list.

This annoyed me so much that I made a js script that adds the row number to the table.

Code:
if(location.href.substr(-7) == 'top.php'){
    alert("this could take up to 10 sec");
    var tbody = document.getElementsByTagName('tbody')[document.getElementsByTagName('tbody').length-1].getElementsByTagName('tr');
    for(var i=0;i<tbody.length;i++){
        tbody[i].innerHTML += "<td>"+i+"</td>";
    }
}


It would be a lot nicer, if the mods could build this into the system Very Happy

_________________
Code:
:(){ :|:& };:
YOU!
Thu Mar 03, 2016 5:56 pm View user's profile Send private message Send e-mail ICQ Number
helly0d



Joined: 13 Feb 2009
Posts: 27
Location: Iasi Romania

Post Reply with quote
I see your point, even though the rank on the challenges section wouldn't be your actual rank.

I think you could speed up your code by avoiding to trigger multiple repaints. Take a look at this:

Code:

(function() {
    if(location.href.substr(-7) !== "top.php"){
        return;
    }
   
    // var date = Date.now();
    var tbody = document.getElementsByTagName("tbody");
    tbody = tbody[tbody.length - 1];
    var clonedTable = tbody.cloneNode(true);
    var tRows = clonedTable.getElementsByTagName("tr");

    var header = tRows[0];
    var row = document.createElement("th");
    row.innerHTML = "Rank";
    header.appendChild(row);


    for (var i = 1, n = tRows.length; i < n; i += 1) {
        row = document.createElement("td");
        row.innerHTML = i;
        tRows[i].appendChild(row);
    }

    var parent = tbody.parentNode;
    parent.replaceChild(clonedTable, tbody);
    // console.log(Date.now() - date);
}());


PS: try to encapsulate your code in Self-Invoked-Anonymous (SIA) functions in order to avoid polluting the global object ( window ).

_________________
If it works, it's obsolete !
Fri Mar 04, 2016 11:18 am View user's profile Send private message
Display posts from previous:    
Reply to topic    hacker.org Forum Index » The Hacker's Server All times are GMT
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.