Files
asimonson1125.github.io/src/static/js/chessbed.js
Claude c8b1f124f2 fix architectural issues: SPA nav, error handling, CSS bugs, perf
- responsive.js: fix scroll race condition (scroll after innerHTML),
  add error handling for fetch failures, fix implicit global `eid`,
  dispatch `beforenavigate` event for cleanup hooks
- chessbed.js: fix implicit global `ratings` variable
- status.js: clear polling interval on SPA navigation via
  `beforenavigate` event to prevent leak
- App.css: add font-display:swap to all @font-face, fix broken
  media query (missing px unit), consolidate duplicate selectors
  (.concentratedHead, .relative, strong), fix hardcoded bookshelf
  background-image path to use relative URL
- header.html: defer chessbed.js, use p5.min.js instead of p5.js
- monitor.py: use ThreadPoolExecutor for concurrent service checks
- config.py: fix __import__('envs.py') → __import__('envs')
- app.py: rename misleading error handlers (page404→handle_http_error,
  page500→handle_generic_error), fix error info leakage by not passing
  raw exception to InternalServerError, fix hardcoded canonical "404"

https://claude.ai/code/session_01FUhPqQLahEoL6FMxhXkDKa
2026-02-12 14:39:43 +00:00

49 lines
1.6 KiB
JavaScript
Executable File

async function addChessEmbed(username) {
let user, stats;
try {
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" });
return;
}
if (user.status === 200) {
user = await user.json();
stats = await stats.json();
const ratings = {
rapid: stats.chess_rapid.last.rating,
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 });
} else if (user === null || user.status === 403 || user.status === null) {
setChess({ cName: "Chess.com request failed" });
} else {
setChess({ cName: "User Not Found" });
}
}
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");
}
}