quality of life improvements (both user and dev)

This commit is contained in:
2023-02-01 21:15:33 -06:00
parent b04dc0504f
commit 3474891c2c
5 changed files with 44 additions and 27 deletions

View File

@@ -34,6 +34,7 @@ body {
background-attachment: fixed;
background-size: 100% auto;
background-clip: border-box;
background-color: #1a1a1a;
}
* {

View File

@@ -4,7 +4,7 @@ async function addChessEmbed(username) {
user = await fetch(`https://api.chess.com/pub/player/${username}`);
stats = await fetch(`https://api.chess.com/pub/player/${username}/stats`);
} catch (e) {
setChess({cName:"Chess.com request failed"});
setChess({ cName: "Chess.com request failed" });
return;
}
if (user.status === 200) {
@@ -15,26 +15,34 @@ async function addChessEmbed(username) {
blitz: stats.chess_blitz.last.rating,
bullet: stats.chess_bullet.last.rating,
tactics: stats.tactics.highest.rating,
}
setChess({cName:user["username"],pic:user.avatar,ratings:ratings});
};
setChess({ cName: user["username"], pic: user.avatar, ratings: ratings });
} else if (user === null || user.status === 403 || user.status === null) {
chessSet({cName:"Chess.com request failed"});
setChess({ cName: "Chess.com request failed" });
} else {
chessSet({cName:"User Not Found"});
setChess({ cName: "User Not Found" });
}
}
function setChess({cName = null, pic = null, ratings = null}) {
if (cName) {
document.querySelector(".chessName").textContent = cName;
}
if (pic) {
document.querySelector(".chessImage").src = pic;
}
if (ratings) {
document.querySelector(".chessRapid .chessStat").textContent = ratings.rapid;
document.querySelector(".chessBlitz .chessStat").textContent = ratings.blitz;
document.querySelector(".chessBullet .chessStat").textContent = ratings.bullet;
document.querySelector(".chessPuzzles .chessStat").textContent = ratings.tactics;
function setChess({ cName = null, pic = null, ratings = null }) {
try {
if (cName) {
document.querySelector(".chessName").textContent = cName;
}
if (pic) {
document.querySelector(".chessImage").src = pic;
}
if (ratings) {
document.querySelector(".chessRapid .chessStat").textContent =
ratings.rapid;
document.querySelector(".chessBlitz .chessStat").textContent =
ratings.blitz;
document.querySelector(".chessBullet .chessStat").textContent =
ratings.bullet;
document.querySelector(".chessPuzzles .chessStat").textContent =
ratings.tactics;
}
} catch {
console.log("fucker clicking so fast the internet can't even keep up");
}
}

View File

@@ -89,8 +89,9 @@ function toggleMenu() {
}
const loc = "https://asimonson.com"
// const loc = 'http://127.0.0.1:5000'
async function goto(location) {
async function goto(location, push=true) {
let a = await fetch(loc + "/api/goto/" + location, {
credentials: "include",
method: "GET",
@@ -105,5 +106,12 @@ async function goto(location) {
eval(x.innerHTML);
});
document.querySelector("title").textContent = metadata['title'];
history.pushState(null, null, metadata['canonical']);
if(push){
history.pushState(null, null, metadata['canonical']);
}
}
function backButton() {
const location = window.location.pathname;
goto(location.substring(1), push=false); // remove slash, goto already does that
}