2025-11-18 21:16:35 -05:00
|
|
|
import { postData, verifyLogin } from "./client.js";
|
|
|
|
|
import { formatSalary } from "./utils.js";
|
|
|
|
|
|
|
|
|
|
const searchForm = document.getElementById("searchForm");
|
|
|
|
|
|
|
|
|
|
const token = window.localStorage.getItem("token");
|
|
|
|
|
|
|
|
|
|
const tableHeader = document.getElementById("header");
|
|
|
|
|
const tableBody = document.getElementById("results");
|
|
|
|
|
const table = document.getElementById("table");
|
|
|
|
|
const nomatch = document.getElementById("nomatch");
|
|
|
|
|
|
2025-11-28 13:54:57 -05:00
|
|
|
|
|
|
|
|
const statsTable = document.querySelector("#stats");
|
|
|
|
|
const statsHeader = document.querySelector("#stats thead");
|
|
|
|
|
const statsBody = document.querySelector("#stats tbody");
|
|
|
|
|
|
|
|
|
|
const overviewHeader = document.querySelector("#overview thead");
|
|
|
|
|
const overviewBody = document.querySelector("#overview tbody");
|
|
|
|
|
|
2025-11-26 21:10:22 -05:00
|
|
|
const watchButton = document.querySelector("#watch");
|
2025-11-28 13:54:57 -05:00
|
|
|
const showStatsButton = document.querySelector("#showStats");
|
2025-11-26 21:10:22 -05:00
|
|
|
|
|
|
|
|
//const watchlist = await postData("/getWatchlist", {}, token);
|
|
|
|
|
|
2025-11-18 21:16:35 -05:00
|
|
|
populatePlayerData();
|
2025-11-26 21:10:22 -05:00
|
|
|
updateIsWatched();
|
|
|
|
|
|
|
|
|
|
watchButton.onclick = async e => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2025-11-28 19:40:43 -05:00
|
|
|
const id = window.location.pathname.split("/")[2].replace("#", "");
|
2025-11-26 21:10:22 -05:00
|
|
|
const resultObject = await postData("/toggleWatched", { id: id }, token);
|
2025-11-28 11:15:58 -05:00
|
|
|
//alert(resultObject.message);
|
2025-11-26 21:10:22 -05:00
|
|
|
updateIsWatched();
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-28 13:54:57 -05:00
|
|
|
showStatsButton.onclick = async e => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2025-11-29 19:02:01 -05:00
|
|
|
statsTable.closest("div").style.display = statsTable.closest("div").style.display == "" ? "none" : "";
|
|
|
|
|
showStatsButton.innerHTML = statsTable.closest("div").style.display == "" ? "Hide Full Stats" : "Show Full Stats";
|
2025-11-28 13:54:57 -05:00
|
|
|
}
|
|
|
|
|
|
2025-11-26 21:10:22 -05:00
|
|
|
async function updateIsWatched() {
|
2025-11-28 19:40:43 -05:00
|
|
|
const id = window.location.pathname.split("/")[2].replace("#", "");
|
2025-11-26 21:10:22 -05:00
|
|
|
const resultObject = await postData("/isWatched", {id: id}, token);
|
|
|
|
|
const isWatched = resultObject.isWatched;
|
|
|
|
|
watchButton.innerHTML = isWatched ? "Stop Watching Player" : "Watch Player";
|
|
|
|
|
}
|
2025-11-18 21:16:35 -05:00
|
|
|
|
|
|
|
|
async function populatePlayerData() {
|
2025-11-28 19:40:43 -05:00
|
|
|
const id = window.location.pathname.split("/")[2].replace("#", "");
|
2025-11-28 13:54:57 -05:00
|
|
|
let resultObject = await postData("/getPlayerStats", {
|
|
|
|
|
playerID: id
|
|
|
|
|
}, token);
|
|
|
|
|
if (resultObject.success === false) {
|
|
|
|
|
console.log("Invalid ID");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const playerStatsObject = resultObject.matches;
|
|
|
|
|
|
|
|
|
|
|
2025-11-28 19:25:31 -05:00
|
|
|
let playerObjectResult = await postData("/getPlayerScores", {
|
|
|
|
|
playerID: id
|
2025-11-28 13:54:57 -05:00
|
|
|
}, token);
|
|
|
|
|
if (playerObjectResult.success === false) {
|
2025-11-18 21:16:35 -05:00
|
|
|
console.log("Invalid ID");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-28 13:54:57 -05:00
|
|
|
const playerObject = playerObjectResult.match;
|
2025-11-28 19:25:31 -05:00
|
|
|
console.log(playerObjectResult);
|
2025-11-28 13:54:57 -05:00
|
|
|
|
|
|
|
|
for (const [attribute, value] of Object.entries(playerObject)) {
|
2025-11-18 21:16:35 -05:00
|
|
|
console.log(`.attribute-${attribute}`);
|
|
|
|
|
document.querySelectorAll(`.attribute-${attribute}`).forEach(element => {
|
2025-11-28 19:25:31 -05:00
|
|
|
if (element.classList.contains("format-weight")) {
|
|
|
|
|
element.textContent = value + " lbs";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (element.classList.contains("format-height")) {
|
|
|
|
|
element.textContent = `${value.split("-")[0]}' ${value.split("-")[1]}"`;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (element.classList.contains("format-integer")) {
|
|
|
|
|
element.textContent = Math.floor(value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-11-18 21:16:35 -05:00
|
|
|
if (element.classList.contains("format-salary")) {
|
|
|
|
|
element.textContent = formatSalary(value);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
element.textContent = value;
|
|
|
|
|
})
|
|
|
|
|
};
|
2025-11-28 19:25:31 -05:00
|
|
|
|
2025-11-28 13:54:57 -05:00
|
|
|
createStatsTable(playerStatsObject);
|
|
|
|
|
createOverviewTable(playerObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function createOverviewTable(playerObject) {
|
|
|
|
|
const tableHeader = overviewHeader;
|
|
|
|
|
const tableBody = overviewBody;
|
|
|
|
|
|
|
|
|
|
nomatch.style.display = "none"
|
|
|
|
|
tableHeader.innerHTML = "";
|
|
|
|
|
const headerRow = document.createElement("tr")
|
|
|
|
|
//Object.keys(resultObject.matches[0]).forEach(attribute => {
|
|
|
|
|
// headerRow.innerHTML += `<td>${attribute}</td>`;
|
|
|
|
|
//});pass_attempts, complete_pass, total_yards, total_tds, interception, receptions, receiving_yards, receiving_touchdown, rush_attempts, rushing_yards, rush_touchdown, fumble
|
|
|
|
|
headerRow.innerHTML += `
|
|
|
|
|
<td>Contract</td>
|
2025-11-28 20:05:34 -05:00
|
|
|
<td>Annual Salary</td>
|
2025-11-28 13:54:57 -05:00
|
|
|
<td>Years</td>
|
|
|
|
|
<td>Duration</td>
|
|
|
|
|
`;
|
|
|
|
|
tableHeader.appendChild(headerRow);
|
|
|
|
|
|
|
|
|
|
tableBody.innerHTML = "";
|
|
|
|
|
const row = playerObject;
|
|
|
|
|
const rowElement = document.createElement("tr");
|
|
|
|
|
|
|
|
|
|
//for (attribute in player) {
|
|
|
|
|
// row.innerHTML += `<td>${player}</td>l`;
|
|
|
|
|
//}
|
|
|
|
|
rowElement.innerHTML = `
|
|
|
|
|
<td>${formatSalary(row.TrueAvgPerYear * row.Years)}</td>
|
|
|
|
|
<td>${formatSalary(row.TrueAvgPerYear)}</td>
|
|
|
|
|
<td>${row.Years}</td>
|
|
|
|
|
<td>${row.StartYear}-${row.EndYear}</td>
|
|
|
|
|
`;
|
|
|
|
|
tableBody.appendChild(rowElement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function createStatsTable(playerObject) {
|
|
|
|
|
const tableHeader = statsHeader;
|
|
|
|
|
const tableBody = statsBody;
|
|
|
|
|
|
|
|
|
|
nomatch.style.display = "none"
|
|
|
|
|
tableHeader.innerHTML = "";
|
|
|
|
|
const headerRow = document.createElement("tr")
|
|
|
|
|
//Object.keys(resultObject.matches[0]).forEach(attribute => {
|
|
|
|
|
// headerRow.innerHTML += `<td>${attribute}</td>`;
|
|
|
|
|
//});pass_attempts, complete_pass, total_yards, total_tds, interception, receptions, receiving_yards, receiving_touchdown, rush_attempts, rushing_yards, rush_touchdown, fumble
|
|
|
|
|
headerRow.innerHTML += `
|
|
|
|
|
<td>Season</td>
|
|
|
|
|
<td>Season Type</td>
|
|
|
|
|
<td>Week</td>
|
|
|
|
|
<td>Pass Attempts</td>
|
|
|
|
|
<td>Complete Passes</td>
|
|
|
|
|
<td>Total Yards</td>
|
|
|
|
|
<td>Total Touchdowns</td>
|
|
|
|
|
<td>Interceptions</td>
|
|
|
|
|
<td>Receptions</td>
|
|
|
|
|
<td>Recieving Yards</td>
|
|
|
|
|
<td>Receiving Touchdowns</td>
|
|
|
|
|
<td>Rush Attempts</td>
|
|
|
|
|
<td>Rushing Yards</td>
|
|
|
|
|
<td>Rushing Touchdowns</td>
|
|
|
|
|
<td>Fumbles</td>
|
|
|
|
|
`;
|
|
|
|
|
tableHeader.appendChild(headerRow);
|
|
|
|
|
|
|
|
|
|
tableBody.innerHTML = "";
|
|
|
|
|
playerObject.forEach(row => {
|
|
|
|
|
const rowElement = document.createElement("tr");
|
|
|
|
|
|
|
|
|
|
//for (attribute in player) {
|
|
|
|
|
// row.innerHTML += `<td>${player}</td>l`;
|
|
|
|
|
//}
|
2025-11-28 19:31:04 -05:00
|
|
|
console.log(row)
|
2025-11-28 13:54:57 -05:00
|
|
|
rowElement.innerHTML = `
|
2025-11-28 19:25:31 -05:00
|
|
|
<td>${row.season}</td>
|
2025-12-02 00:00:51 -05:00
|
|
|
<td>${row.seasontype == "REG" ? "Reg" : "Post"}</td>
|
2025-11-28 19:25:31 -05:00
|
|
|
<td>${row.week}</td>
|
2025-11-28 13:54:57 -05:00
|
|
|
<td>${row.pass_attempts}</td>
|
|
|
|
|
<td>${row.complete_pass}</td>
|
|
|
|
|
<td>${row.total_yards}</td>
|
|
|
|
|
<td>${row.total_tds}</td>
|
|
|
|
|
<td>${row.interception}</td>
|
|
|
|
|
<td>${row.receptions}</td>
|
|
|
|
|
<td>${row.receiving_yards}</td>
|
|
|
|
|
<td>${row.receiving_touchdown}</td>
|
|
|
|
|
<td>${row.rush_attempts}</td>
|
|
|
|
|
<td>${row.rushing_yards}</td>
|
|
|
|
|
<td>${row.rush_touchdown}</td>
|
|
|
|
|
<td>${row.fumble}</td>
|
|
|
|
|
`;
|
|
|
|
|
tableBody.appendChild(rowElement);
|
|
|
|
|
});
|
2025-11-18 21:16:35 -05:00
|
|
|
}
|
2025-11-28 13:54:57 -05:00
|
|
|
//});pass_attempts, complete_pass, total_yards, total_tds, interception, receptions, receiving_yards, receiving_touchdown, rush_attempts, rushing_yards, rush_touchdown, fumble
|