You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
ITLRankTracker/tracker.js

39 lines
1.8 KiB

console.log("Hello World!");
var targetPlayer="sigonasr2";
var prevRankData;
var currentPlayerData;
var nextRankData;
function DisplayPlayerInfo(pl,showTotal=false){
return "<div><span class=\"rankSymbol\">#</span><span class=\"rank\">"+pl.position+"</span>"+
(showTotal?"<span class=\"rankTotal\">/"+pl.leaderboardSize+"</span>":"")+`
<span class=\"name\">`+pl.name+`</span>
<span class=\"points\">`+pl.rankingPoints+" pts</span></div>";
}
function GetData(){
fetch("http://projectdivar.com/files/leaderboardinfo", {cache: "no-cache"}).then((resp)=>resp.json())
.then((data)=>{
for(i=0;i<data.data.leaderboard.length;i++){
var member = data.data.leaderboard[i];
if (member.name===targetPlayer){
currentPlayerData=member;
currentPlayerData.position=i+1
currentPlayerData.leaderboardSize=data.data.leaderboard.length
}
}
nextRankData={...data.data.leaderboard[currentPlayerData.position-2],position:currentPlayerData.position-1};
prevRankData={...data.data.leaderboard[currentPlayerData.position],position:currentPlayerData.position+1};
document.getElementById("playerRank").innerHTML="<div class=\"player\">"+DisplayPlayerInfo(currentPlayerData,true)+"</div>"
if (prevRankData){
document.getElementById("prevRank").innerHTML="<div class=\"prevRank\">"+DisplayPlayerInfo(prevRankData)+"</div>";
}else{
document.getElementById("prevRank").innerHTML="";
}
if (nextRankData){
document.getElementById("nextRank").innerHTML="<div class=\"nextRank\">"+DisplayPlayerInfo(nextRankData)+"</div>";
}else{
document.getElementById("nextRank").innerHTML="";
}
})
}
GetData();
setInterval(GetData,5000);