var hiscores = hiscores || {};
hiscores.sName = [
"Attack",
"Defence",
"Strength",
"Constitution",
"Ranged",
"Prayer",
"Magic",
"Cooking",
"Woodcutting",
"Fletching",
"Fishing",
"Firemaking",
"Crafting",
"Smithing",
"Mining",
"Herblore",
"Agility",
"Thieving",
"Slayer",
"Farming",
"Runecrafting",
"Hunter",
"Construction",
"Summoning"
]
hiscores.page = 0;
hiscores.currentSkillId = "";
hiscores.apiURL = "http://api.2009scape.org:3000";
hiscores.tableData = [];
hiscores.defaultTableData = [];
hiscores.linkLeftTabSkillNames = () => {
hiscores.sName.forEach((skill, index) => {
row = document.getElementsByClassName(` ${skill} ico`)[0].addEventListener("click", function (e) {
hiscores.page = 0;
hiscores.loadSkillTable(index);
});
});
}
hiscores.initializePageArrows = () => {
document.getElementById("button-up").addEventListener("click", function (e) {
e.preventDefault();
if (hiscores.page > 0) {
hiscores.page--;
}
let pageRemovedWindowLocation = window.location.search.split(/\?page=\d*/).join('');
window.location.replace(`./hiscores.html${pageRemovedWindowLocation}?page=${hiscores.page}`);
});
document.getElementById("button-down").addEventListener("click", function (e) {
e.preventDefault();
hiscores.page++;
let pageRemovedWindowLocation = window.location.search.split(/\?page=\d*/).join('');
window.location.replace(`./hiscores.html${pageRemovedWindowLocation}?page=${hiscores.page}`);
});
}
hiscores.initalizeRightsideButtons = () => {
document.getElementById("search_button").addEventListener("click", function (e) {
e.preventDefault();
window.location.replace(`./hiscores.html?player=${document.getElementById('search_name').value}`);
});
document.getElementById("search_rank_submit").addEventListener("click", function (e) {
e.preventDefault();
if (document.getElementById('search_rank').value) {
hiscores.loadUserTable(hiscores.defaultTableData[document.getElementById('search_rank').value - 1].username)
hiscores.setHeadSkillText(hiscores.defaultTableData[document.getElementById('search_rank').value - 1].username + "'s ");
}
else {
hiscores.loadDefaultHSTable();
}
});
document.getElementById("filter_submit").addEventListener("click", function (e) {
e.preventDefault();
hiscores.page++;
let pageRemovedFiltersLocation = window.location.search.split(/\?iron=[A-z]+|\?ultiron=[A-z]+|\?hciron=[A-z]+|\?maxXP=\d+/).join('');
const ironparam = `?iron=${document.getElementById('check_iron').checked}`;
const ultironparam = `?ultiron=${document.getElementById('check_ultiron').checked}`;
const hcironparam = `?hciron=${document.getElementById('check_hciron').checked}`;
const maxXP = `?maxXP=${document.getElementById("maxXP").value}`;
window.location.replace(`./hiscores.html${pageRemovedFiltersLocation}${ironparam}${ultironparam}${hcironparam}${maxXP}`);
});
}
hiscores.formatName = (name, ironStatus = 0, xpRate = 10, aposS = false,) => {
name = name.replaceAll("_", " ");
name = name.replace(/(^\w|\s\w)/g, match => match.toUpperCase()); // Capitalize first letter of each word
if (aposS) {
if (!name.endsWith('s')) {
name += "'s";
} else {
name += "'";
}
}
name = hiscores.getIronIcon(ironStatus) + name;
if (xpRate != 10) {
return name + ` ${xpRate > 10 ? Math.round(xpRate) : xpRate}x`;
}
return name;
}
hiscores.setHeadSkillIcon = (icon) => {
if (icon.includes(".")) {
document.getElementById("scores_head_icon").src = icon;
} else {
document.getElementById("scores_head_icon").src = `../../site/img/hiscores/skill_icon_${icon.toLowerCase()}1eccb.gif`;
}
}
hiscores.setHeadSkillText = (text) => {
document.getElementById("scores_head_skill").innerHTML = text;
}
hiscores.getIronIcon = (ironStatus) => {
switch (ironStatus) {
case "1":
case 1:
return ` `;
case "2":
case 2:
return ` `;
case "3":
case 3:
return ` `;
default:
return "";
}
}