Author |
Message |
Napoleon
Joined: 11 Dec 2010 Posts: 23 Location: Faroe Islands |
|
JS Rank calculator |
|
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.
 |
 |
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 
_________________
 |
 |
:(){ :|:& };: |
YOU! |
|
Thu Mar 03, 2016 5:56 pm |
 |
 |
helly0d
Joined: 13 Feb 2009 Posts: 29 Location: Iasi Romania |
|
|
|
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:
 |
 |
(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 |
|
 |
|
|
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
|
|
|