2023-09-14 07:17:41 -04:00
|
|
|
// Sourced from ryanparag on CodePen
|
|
|
|
|
|
|
|
console.clear();
|
|
|
|
|
|
|
|
const tableRow = document.querySelectorAll(".list__row");
|
|
|
|
const overlay = document.querySelector(".overlay");
|
|
|
|
const sidebar = document.querySelector(".sidebar");
|
|
|
|
const closeOverlayBtn = document.querySelector(".button--close");
|
|
|
|
|
|
|
|
const sidebarClose = () => {
|
|
|
|
sidebar.classList.remove("is-open");
|
|
|
|
overlay.style.opacity = 0;
|
|
|
|
setTimeout(() => {
|
|
|
|
overlay.classList.remove("is-open");
|
|
|
|
overlay.style.opacity = 1;
|
|
|
|
}, 300);
|
|
|
|
};
|
|
|
|
|
2023-09-15 17:54:33 -04:00
|
|
|
function formatTable(){
|
|
|
|
const tableRow = document.querySelectorAll(".list__row");
|
2023-09-14 07:17:41 -04:00
|
|
|
tableRow.forEach(tableRow => {
|
|
|
|
tableRow.addEventListener("click", function () {
|
|
|
|
overlay.style.opacity = 0;
|
|
|
|
overlay.classList.add("is-open");
|
|
|
|
sidebar.classList.add("is-open");
|
|
|
|
setTimeout(() => {
|
|
|
|
overlay.style.opacity = 1;
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
// Sidebar content
|
|
|
|
const sidebarBody = document.querySelector(".sidebar__body");
|
|
|
|
sidebarBody.innerHTML = '';
|
|
|
|
|
2023-09-20 07:53:30 -04:00
|
|
|
const ninjaName = this.querySelector(".list__cell:nth-of-type(2) .list__value").innerHTML;
|
|
|
|
const ninjaBelt = this.querySelector(".list__cell:nth-of-type(4) .list__value").innerHTML;
|
|
|
|
const ninjaLevel = this.querySelector(".list__cell:nth-of-type(5) .list__value").innerHTML;
|
|
|
|
const ninjaPicture = this.dataset.image;
|
2023-09-15 17:54:33 -04:00
|
|
|
const ninjaActivity = this.dataset.activity;
|
2023-09-20 07:53:30 -04:00
|
|
|
const ninjaActivityImg = this.dataset.country;
|
2023-09-14 07:17:41 -04:00
|
|
|
|
2023-09-20 07:53:30 -04:00
|
|
|
const newNinja = document.createElement('div');
|
|
|
|
newNinja.classList = 'driver';
|
2023-09-14 07:17:41 -04:00
|
|
|
|
2023-09-20 07:53:30 -04:00
|
|
|
const ninjaContent = document.createElement('div');
|
|
|
|
ninjaContent.classList = 'driver__content';
|
2023-09-14 07:17:41 -04:00
|
|
|
|
|
|
|
const profile = document.createElement('div');
|
|
|
|
profile.classList = 'driver__image';
|
2023-09-20 07:53:30 -04:00
|
|
|
profile.style.backgroundImage = `url('/assets/img/belts/${ninjaBelt}.png')`;
|
|
|
|
newNinja.appendChild(profile);
|
2023-09-14 07:17:41 -04:00
|
|
|
|
2023-09-20 07:53:30 -04:00
|
|
|
const ninjaTitle = document.createElement('div');
|
|
|
|
ninjaTitle.classList = 'driver__title';
|
|
|
|
ninjaTitle.innerHTML = ninjaName;
|
|
|
|
ninjaContent.appendChild(ninjaTitle);
|
2023-09-14 07:17:41 -04:00
|
|
|
|
2023-09-20 07:53:30 -04:00
|
|
|
activityNames = {
|
|
|
|
'Build 1':'build',
|
|
|
|
'Build 2':'build',
|
|
|
|
'Quest':'project',
|
|
|
|
'Explore':'explore',
|
|
|
|
'Adventure':'solve'
|
|
|
|
}
|
|
|
|
|
|
|
|
const ninjaInfo = document.createElement('div');
|
|
|
|
ninjaInfo.innerHTML = `
|
2023-09-14 07:17:41 -04:00
|
|
|
<table class="driver__table">
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
2023-09-24 07:12:09 -04:00
|
|
|
<td class="sidebar-td"><small>Belt</small></td>
|
2023-09-20 07:53:30 -04:00
|
|
|
<td class="caps">${ninjaBelt}</td>
|
2023-09-14 07:17:41 -04:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><small>Level</small></td>
|
2023-09-20 07:53:30 -04:00
|
|
|
<td class="caps">${ninjaLevel}</td>
|
2023-09-14 07:17:41 -04:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td><small>Activity</small></td>
|
2023-09-20 07:53:30 -04:00
|
|
|
<td><img class="activity-badge" src="/assets/img/activity/${activityNames[ninjaActivity]}.png"><span>${ninjaActivity}</span></td>
|
2023-09-14 07:17:41 -04:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2023-09-16 02:16:16 -04:00
|
|
|
<td><small>Score</small></td>
|
2023-09-20 07:53:30 -04:00
|
|
|
<td class="caps">${this.dataset.score} </td>
|
2023-09-16 02:16:16 -04:00
|
|
|
</tr>
|
2023-09-24 07:12:09 -04:00
|
|
|
|
2023-09-16 02:16:16 -04:00
|
|
|
<tr>
|
2023-09-24 07:12:09 -04:00
|
|
|
<td><small>Last Updated On</small></td>
|
|
|
|
<td>${timeSince(this.dataset.Timestamp)}</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td class="center bold" colspan=2>${this.dataset.remark} </td>
|
2023-09-14 07:17:41 -04:00
|
|
|
</tr>
|
|
|
|
|
|
|
|
</tbody>
|
|
|
|
</table>`;
|
2023-09-20 07:53:30 -04:00
|
|
|
ninjaContent.appendChild(ninjaInfo);
|
2023-09-14 07:17:41 -04:00
|
|
|
|
2023-09-20 07:53:30 -04:00
|
|
|
newNinja.appendChild(ninjaContent);
|
|
|
|
sidebarBody.appendChild(newNinja);
|
2023-09-14 07:17:41 -04:00
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2023-09-15 17:54:33 -04:00
|
|
|
}
|
2023-09-14 07:17:41 -04:00
|
|
|
|
|
|
|
closeOverlayBtn.addEventListener("click", function () {
|
|
|
|
sidebarClose();
|
|
|
|
});
|
|
|
|
|
|
|
|
overlay.addEventListener("click", function () {
|
|
|
|
sidebarClose();
|
2023-09-24 07:12:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function timeSince(timestring) {
|
|
|
|
var timeStamp = new Date(timestring);
|
|
|
|
var now = new Date(),
|
|
|
|
secondsPast = (now.getTime() - timeStamp) / 1000;
|
|
|
|
if (secondsPast < 60) {
|
|
|
|
return parseInt(secondsPast) + ' seconds ago';
|
|
|
|
}
|
|
|
|
if (secondsPast < 3600) {
|
|
|
|
return parseInt(secondsPast / 60) + ' minutes ago';
|
|
|
|
}
|
|
|
|
if (secondsPast <= 86400) {
|
|
|
|
return parseInt(secondsPast / 3600) + ' hours ago';
|
|
|
|
}
|
|
|
|
if (secondsPast > 86400) {
|
|
|
|
day = timeStamp.getDate();
|
|
|
|
month = timeStamp.toDateString().match(/ [a-zA-Z]*/)[0].replace(" ", "");
|
|
|
|
year = timeStamp.getFullYear() == now.getFullYear() ? "" : " " + timeStamp.getFullYear();
|
|
|
|
return day + " " + month + year;
|
|
|
|
}
|
|
|
|
}
|