2020-12-31 21:10:39 +01:00
|
|
|
var hiscores = hiscores || {};
|
|
|
|
|
2021-01-07 22:21:34 +01:00
|
|
|
let activityInfo = [];
|
|
|
|
|
2020-12-31 21:10:39 +01:00
|
|
|
hiscores.populateActivityTable = () => {
|
|
|
|
row = (num) => document.getElementsByClassName(`row row${num}`)[0]; // Small wrapper that gets a row by just the row #
|
|
|
|
|
|
|
|
// Clear it
|
2021-01-05 17:17:18 +01:00
|
|
|
for (let i = 1; i <= 24; i++) {
|
2020-12-31 21:10:39 +01:00
|
|
|
row(i).childNodes[1].replaceWith(document.createElement("td"));
|
|
|
|
row(i).childNodes[1].className = "rankCol";
|
2021-01-05 17:17:18 +01:00
|
|
|
row(i).childNodes[1].innerHTML = i;
|
2020-12-31 21:10:39 +01:00
|
|
|
|
|
|
|
row(i).childNodes[3].replaceWith(document.createElement("td"));
|
|
|
|
row(i).childNodes[3].className = "alL";
|
|
|
|
row(i).childNodes[3].innerHTML = "";
|
|
|
|
|
|
|
|
row(i).childNodes[5].replaceWith(document.createElement("td"));
|
|
|
|
row(i).childNodes[5].className = "alL";
|
|
|
|
row(i).childNodes[5].innerHTML = "";
|
|
|
|
}
|
|
|
|
|
2021-01-07 22:52:23 +01:00
|
|
|
// (Used to make all the amounts update at once)
|
|
|
|
let leftToLoad = activityInfo.length;
|
|
|
|
let toAppear = [];
|
|
|
|
function syncAppear(element, value) {
|
|
|
|
leftToLoad --;
|
|
|
|
toAppear.push([element, value]);
|
|
|
|
console.log(leftToLoad);
|
|
|
|
if (leftToLoad === 0) {
|
|
|
|
toAppear.forEach(([e, value]) => {
|
|
|
|
e.innerHTML = value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For everything on this page (see the filter? in URL)
|
2021-01-07 22:21:34 +01:00
|
|
|
activityInfo.forEach(([title, endpoint, resultAttr], index) => {
|
2021-01-07 21:49:24 +01:00
|
|
|
row(index + 1).childNodes[3].innerHTML = title;
|
|
|
|
row(index + 1).childNodes[5].innerHTML = `<span style="color: rgba(186, 128, 63, 0.4);">Loading..</span>`;
|
2021-01-07 22:52:23 +01:00
|
|
|
// Fetch it, then put it in our synchronous appearance function
|
2021-02-15 18:07:22 +01:00
|
|
|
fetch(`${hiscores.apiURL}/hiscores/${endpoint}/${restrictions}`)
|
2021-01-07 21:49:24 +01:00
|
|
|
.then(response => response.json())
|
2021-01-07 22:52:23 +01:00
|
|
|
.then(result => {
|
|
|
|
syncAppear(row(index + 1).childNodes[5], Math.floor(result[`${resultAttr}`]).toLocaleString());
|
2021-01-07 21:49:24 +01:00
|
|
|
})
|
|
|
|
.catch(error => console.log('error', error));
|
|
|
|
});
|
2020-12-31 21:10:39 +01:00
|
|
|
}
|
|
|
|
|
2021-01-07 22:21:34 +01:00
|
|
|
hiscores.enterTotalXp = () => {
|
2021-02-16 23:58:19 +01:00
|
|
|
fetch(`${hiscores.apiURL}/hiscores/getWorldTotalXp/${hiscores.world}/${restrictions}`)
|
2021-01-07 22:21:34 +01:00
|
|
|
.then(response => response.json())
|
|
|
|
.then(result => {
|
|
|
|
document.getElementById("total_xp").innerText = "Server Total XP: " + Math.round(result.total_xp).toLocaleString();
|
|
|
|
document.getElementById("total_xp").style.opacity = "1";
|
|
|
|
})
|
|
|
|
.catch(error => console.log('error', error));
|
|
|
|
}
|
|
|
|
|
2020-12-31 21:10:39 +01:00
|
|
|
/**
|
|
|
|
* In URL ?player=guthix, passing param "player" will return "guthix"
|
|
|
|
* In same example, passing param "page" will return null
|
|
|
|
*/
|
|
|
|
function getParam(param) {
|
|
|
|
param = window.location.search.split("?").find(p => {
|
|
|
|
return p.startsWith(`${param}`);
|
|
|
|
})
|
|
|
|
return param ? param.split("=")[1] : null;
|
|
|
|
}
|
|
|
|
|
2021-01-05 17:17:18 +01:00
|
|
|
let restrictions = { ironManMode: [], exp_multiplier: 10 };
|
|
|
|
|
2021-02-15 07:47:54 +01:00
|
|
|
if (getParam("world")) {
|
|
|
|
hiscores.world = Number(getParam("world"));
|
|
|
|
}
|
2020-12-31 21:10:39 +01:00
|
|
|
if (getParam("page")) {
|
|
|
|
hiscores.page = Number(getParam("page"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getParam("iron")) {
|
|
|
|
document.getElementById('check_iron').checked = getParam("iron") === "true";
|
2021-01-05 17:17:18 +01:00
|
|
|
restrictions.ironManMode.push(getParam("iron") === "true" ? "1" : "0");
|
2020-12-31 21:10:39 +01:00
|
|
|
|
|
|
|
document.getElementById("filter_submit").value = "Filter";
|
|
|
|
document.getElementById("filter_div").style.height = "134px";
|
|
|
|
// Add disable button
|
|
|
|
document.getElementById("filter_clear_div").innerHTML = `<input id="filter_clear" type="submit" name="submit" class="buttonmedium" value="Clear" style="margin-top: 2px;">`
|
|
|
|
} else {
|
|
|
|
document.getElementById("filter_clear_div").innerHTML = "";
|
|
|
|
// Change width to 134 minus button size
|
|
|
|
document.getElementById("filter_div").style.height = "110px";
|
|
|
|
}
|
|
|
|
if (getParam("ultiron")) {
|
2021-01-05 17:17:18 +01:00
|
|
|
restrictions.ironManMode.push(getParam("ultiron") === "true" ? "3" : "0");
|
2020-12-31 21:10:39 +01:00
|
|
|
document.getElementById('check_ultiron').checked = getParam("ultiron") === "true";
|
|
|
|
}
|
|
|
|
if (getParam("hciron")) {
|
2021-01-05 17:17:18 +01:00
|
|
|
restrictions.ironManMode.push(getParam("hciron") === "true" ? "2" : "0");
|
2020-12-31 21:10:39 +01:00
|
|
|
document.getElementById('check_hciron').checked = getParam("hciron") === "true";
|
|
|
|
}
|
|
|
|
if (getParam("maxXP")) {
|
2021-01-05 17:17:18 +01:00
|
|
|
restrictions.exp_multiplier = Number(getParam("maxXP"));
|
|
|
|
|
2020-12-31 21:10:39 +01:00
|
|
|
document.getElementById('maxXP').value = getParam("maxXP");
|
|
|
|
document.getElementById('maxXPoutput').innerHTML = getParam("maxXP");
|
|
|
|
}
|
2021-01-07 22:21:34 +01:00
|
|
|
switch (getParam("filter")) {
|
|
|
|
case "combat":
|
2021-01-07 22:27:12 +01:00
|
|
|
document.getElementById("scores_head_skill").innerText = "Combat";
|
2021-02-15 18:07:22 +01:00
|
|
|
activityInfo.push(["Total Slayer Tasks Completed", `getWorldTotalSlayerTasks/${hiscores.world}`, "total_tasks"]);
|
|
|
|
activityInfo.push(["Total Enemies Killed", `getWorldTotalAttribute/${hiscores.world}/enemies_killed`, "sum"]);
|
|
|
|
activityInfo.push(["Total Deaths", `getWorldTotalAttribute/${hiscores.world}/deaths`, "sum"]);
|
2021-01-07 22:21:34 +01:00
|
|
|
break;
|
|
|
|
case "miscellaneous":
|
2021-01-07 22:27:12 +01:00
|
|
|
document.getElementById("scores_head_skill").innerText = "Miscellaneous";
|
2021-02-15 18:07:22 +01:00
|
|
|
activityInfo.push(["Total Al Kharid Gate Tax", `getWorldTotalAttribute/${hiscores.world}/alkharid_gate`, "sum"]);
|
2021-01-07 22:21:34 +01:00
|
|
|
break;
|
|
|
|
default: // Skilling
|
2021-02-15 18:07:22 +01:00
|
|
|
activityInfo.push(["Total Logs Chopped", `getWorldTotalAttribute/${hiscores.world}/logs_chopped`, "sum"]);
|
|
|
|
activityInfo.push(["Total Fish Caught", `getWorldTotalAttribute/${hiscores.world}/fish_caught`, "sum"]);
|
|
|
|
activityInfo.push(["Total Rocks Mined", `getWorldTotalAttribute/${hiscores.world}/rocks_mined`, "sum"]);
|
2021-01-07 22:21:34 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-12-31 21:10:39 +01:00
|
|
|
|
2021-01-05 17:17:18 +01:00
|
|
|
restrictions = JSON.stringify(restrictions);
|
2020-12-31 21:10:39 +01:00
|
|
|
|
2021-01-07 22:21:34 +01:00
|
|
|
hiscores.linkLeftTabActivityNames("activity");
|
2021-01-05 17:17:18 +01:00
|
|
|
hiscores.initializePageArrows("activity");
|
|
|
|
hiscores.initalizeRightsideButtons("activity");
|
2021-01-07 22:21:34 +01:00
|
|
|
hiscores.populateActivityTable("activity");
|
2021-02-16 23:52:21 +01:00
|
|
|
hiscores.enterTotalXp();
|
|
|
|
hiscores.changePlaqueWorld();
|
|
|
|
hiscores.addSkillsAndActivityFilters();
|