-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9007f1
commit d061a9a
Showing
7 changed files
with
291 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<title>QB Reader</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta name="description" content="Select a geoword division."> | ||
|
||
<link href="/apple-touch-icon.png" rel="apple-touch-icon"> | ||
<link href="/apple-touch-icon-precomposed.png" rel="apple-touch-icon-precomposed"> | ||
<link type="image/x-icon" href="/favicon.ico" rel="icon"> | ||
|
||
<link href="/bootstrap/light.css" rel="stylesheet"> | ||
<link href="/bootstrap/dark.css" rel="stylesheet" id="custom-css"> | ||
<script src="/apply-theme.js"></script> | ||
</head> | ||
|
||
<body> | ||
<nav class="navbar navbar-light navbar-expand-lg bg-custom" id="navbar" style="z-index: 10"> | ||
<div class="container-fluid"> | ||
<a class="navbar-brand ms-1 py-0" id="logo" href="/"> | ||
<span class="logo-prefix">QB</span><span class="logo-suffix">Reader</span> | ||
</a> | ||
<button class="navbar-toggler" data-bs-target="#navbarSupportedContent" data-bs-toggle="collapse" type="button" | ||
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
<div class="collapse navbar-collapse" id="navbarSupportedContent"> | ||
<ul class="navbar-nav me-auto mb-2 mb-lg-0"> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="/tossups">Tossups</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="/bonuses">Bonuses</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="/multiplayer">Multiplayer</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="/db">Database</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link active" href="/geoword">Geoword</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="/api-docs">API</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="/about">About</a> | ||
</li> | ||
</ul> | ||
<div class="d-flex"> | ||
<ul class="navbar-nav mb-2 mb-lg-0"> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="/user/login" id="login-link">Log in</a> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</nav> | ||
|
||
<div class="container-xl mt-3 mb-5 pb-5"> | ||
<p> | ||
Compare your stats on <b id="packet-name"></b> (<span id="division"></span>) against another player. | ||
</p> | ||
<form class="mb-3" id="form"> | ||
<div class="mb-3"> | ||
<label for="opponent" class="form-label">Enter a username here:</label> | ||
<input type="text" class="form-control" id="opponent"> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Submit</button> | ||
</form> | ||
<div id="root"></div> | ||
</div> | ||
|
||
<script src="/bootstrap/bootstrap.bundle.min.js"></script> | ||
<script src="/script.js"></script> | ||
|
||
<script src="/geoword/script.js"></script> | ||
<script src="/geoword/compare.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
const packetName = window.location.pathname.split('/').pop(); | ||
const packetTitle = titleCase(packetName); | ||
document.getElementById('packet-name').textContent = packetTitle; | ||
|
||
let division; | ||
|
||
fetch('/api/geoword/division-choice?' + new URLSearchParams({ packetName })) | ||
.then(response => response.json()) | ||
.then(data => { | ||
division = data.division; | ||
document.getElementById('division').textContent = division; | ||
}); | ||
|
||
document.getElementById('form').addEventListener('submit', event => { | ||
event.preventDefault(); | ||
|
||
const opponent = document.getElementById('opponent').value; | ||
|
||
fetch('/api/geoword/compare?' + new URLSearchParams({ packetName, division, opponent })) | ||
.then(response => response.json()) | ||
.then(data => { | ||
const { myBuzzes, opponentBuzzes } = data; | ||
|
||
if (myBuzzes.length === 0) { | ||
document.getElementById('root').innerHTML = ` | ||
<div class="alert alert-danger" role="alert"> | ||
No stats found for you. | ||
</div>`; | ||
return; | ||
} | ||
|
||
if (opponentBuzzes.length === 0) { | ||
document.getElementById('root').innerHTML = ` | ||
<div class="alert alert-danger" role="alert"> | ||
No stats found for ${escapeHTML(opponent)}. | ||
</div>`; | ||
return; | ||
} | ||
|
||
let myPoints = 0; | ||
let myTossupCount = 0; | ||
let opponentPoints = 0; | ||
let opponentTossupCount = 0; | ||
|
||
let innerHTML = ''; | ||
|
||
for (let i = 0; i < Math.min(myBuzzes.length, opponentBuzzes.length); i++) { | ||
const myBuzz = myBuzzes[i]; | ||
const opponentBuzz = opponentBuzzes[i]; | ||
|
||
if (myBuzz.points > 0 && opponentBuzz.points === 0) { | ||
myPoints += myBuzz.points; | ||
myTossupCount++; | ||
} else if (myBuzz.points === 0 && opponentBuzz.points > 0) { | ||
opponentPoints += opponentBuzz.points; | ||
opponentTossupCount++; | ||
} else if (myBuzz.points > 0 && opponentBuzz.points > 0) { | ||
if (myBuzz.celerity > opponentBuzz.celerity) { | ||
myPoints += myBuzz.points; | ||
myTossupCount++; | ||
} else if (myBuzz.celerity < opponentBuzz.celerity) { | ||
opponentPoints += opponentBuzz.points; | ||
opponentTossupCount++; | ||
} else { | ||
myPoints += myBuzz.points / 2; | ||
myTossupCount++; | ||
opponentPoints += opponentBuzz.points / 2; | ||
opponentTossupCount++; | ||
} | ||
} | ||
|
||
innerHTML += ` | ||
<hr> | ||
<div class="row mb-3"> | ||
<div class="col-6"> | ||
<div><b>#${myBuzz.questionNumber}</b></div> | ||
<div><b>Celerity:</b> ${(myBuzz.celerity ?? 0.0).toFixed(3)}</div> | ||
<div><b>Points:</b> ${myBuzz.points}</div> | ||
<div><b>Given answer:</b> ${escapeHTML(myBuzz.givenAnswer)}</div> | ||
</div> | ||
<div class="col-6"> | ||
<div><b>Answer:</b> ${removeParentheses(myBuzz.formatted_answer ?? myBuzz.answer)}</div> | ||
<div><b>Celerity:</b> ${(opponentBuzz.celerity ?? 0.0).toFixed(3)}</div> | ||
<div><b>Points:</b> ${opponentBuzz.points}</div> | ||
<div><b>Given answer:</b> ${escapeHTML(opponentBuzz.givenAnswer)}</div> | ||
</div> | ||
</div>`; | ||
} | ||
|
||
innerHTML = ` | ||
<div class="row mb-3"> | ||
<div class="text-center col-6"> | ||
<div class="lead">Your stats:</div> | ||
${myPoints} points (${myTossupCount} tossups) | ||
</div> | ||
<div class="text-center col-6"> | ||
<div class="lead">${escapeHTML(opponent)}'s stats:</div> | ||
${opponentPoints} points (${opponentTossupCount} tossups) | ||
</div> | ||
</div> | ||
` + innerHTML; | ||
|
||
|
||
|
||
document.getElementById('root').innerHTML = innerHTML; | ||
}); | ||
}); | ||
|
||
function removeParentheses(answer) { | ||
return answer.replace(/[([].*/g, ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters