Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized the code and hopefully made it more readable #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 52 additions & 48 deletions database.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
var loadingEl = document.createElement("p");
var loadingText = document.createTextNode("Loading...");
loadingEl.appendChild(loadingText);
document.getElementById("databaseTable").appendChild(loadingEl);
var url = document.URL.split("/");
var category = url[url.length - 2];
var game = url[url.length - 3];
const loadingEl = document.createElement("p");
loadingEl.setAttribute("id", "loading");
loadingEl.innerText = "Loading...";
const elem = document.getElementById("databaseTable");
elem.appendChild(loadingEl);
const url = document.URL.split("/");
const category = url[url.length - 2];
const game = url[url.length - 3];
let totalDash = 0; // :roundelie:
let totalJump = 0;
let totalLeftPress = 0;
let totalRightPress = 0;
let database;
let xhr = new XMLHttpRequest();
xhr.open("GET", "../../database.json");
xhr.send();
xhr.onload = () => {
database = JSON.parse(xhr.responseText);
// Format is database['game']['category']
// If unsure check out database.json
document.getElementById("fulltime").innerText = database["fulltime"][game][category]
database = database[game][category.toLowerCase()];
let mindashes=category.toLocaleLowerCase().includes('dash')
let minjumps=category.toLocaleLowerCase().includes('jump')
let elem=document.getElementById("databaseTable")
for (i = 0; i < database.length; i++) {
elem.innerHTML +=
'<tr><td>' + (database[i]['file'] == null ? "" : '<a href=' + database[i]['file'] + ' download>') + database[i]['name'] + '</a></td>' +
'<td>' + (database[i]['frames'] == null ? "" : database[i]['frames'] + 'f') + '</td>'+
(mindashes?('<td>' + database[i]['dashes'] +'d</td>'):(minjumps?('<td>' + database[i]['jumps'] +'j</td>'):'')) +'</tr>';
totalDash += database[i]['dashes'];
totalJump += database[i]['jumps'];
}
loadingEl.style.display = 'none';
}
// Old, used for the loading text when the page was slow
// Just a relic now
// Still works on slow connections
xhr.onreadystatechange = function () {
loadingEl.style.display = 'none';
//document.getElementById('category').innerHTML = category;
if(category.toLocaleLowerCase().includes('dash')){
setTimeout(function () {
document.getElementById('totaldashes').innerHTML = totalDash;
}, 1);
}
if(category.toLocaleLowerCase().includes('jump')){
setTimeout(function () {
document.getElementById('totaljumps').innerHTML = totalJump;
}, 1);
}
const totalRightPress = 0;
fetch("../../database.json")
.then((response) => response.json())
.then((database) => {
// Format is database['game']['category']
// If unsure check out database.json
document.getElementById("fulltime").innerText =
database["fulltime"][game][category];
database = database[game][category.toLowerCase()];
let mindashes = category.toLocaleLowerCase().includes("dash");
let minjumps = category.toLocaleLowerCase().includes("jump");

}
for (i in database) {
elem.innerHTML += `<tr><td>
${database[i]["file"] == null ? "" : `<a href=${database[i]["file"]} download>`}
${database[i]["name"]}</a></td>
<td>${database[i]["frames"] == null ? "" : `${database[i]["frames"]}f`}
</td>
${
mindashes
? `<td>${database[i]["dashes"]}d</td>`
: minjumps
? `<td>${database[i]["jumps"]}j</td>`
: ""
}
</tr>`;
totalDash += database[i]["dashes"];
totalJump += database[i]["jumps"];
}
// Old, used for the loading text when the page was slow
// Just a relic now
// Still works on slow connections
document.getElementById("loading").style.display = "none";
//document.getElementById('category').innerHTML = category;
if (category.toLocaleLowerCase().includes("dash")) {
setTimeout(() => {
document.getElementById("totaldashes").innerText = totalDash;
}, 1);
}
if (category.toLocaleLowerCase().includes("jump")) {
setTimeout(() => {
document.getElementById("totaljumps").innerText = totalJump;
}, 1);
}
});