diff --git a/assets/css/main.css b/assets/css/main.css index 570e4ec..ddd589d 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -142,7 +142,11 @@ input[type=text] { flex: 1; } -.info:hover { +.info i { + transition: all 0.2s; +} + +.info i:hover { color: #D3D3D3; cursor: pointer; } diff --git a/assets/js/main.js b/assets/js/main.js index 121ab06..fb29a11 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -247,23 +247,7 @@ async function submit(guess, real) { } let stats = JSON.parse(localStorage.stats) let scores = JSON.parse(localStorage.scores) - let bars = ["one", "two", "three", "four", "five", "six"] - bars.forEach((bar, index) => { - document.getElementById(bar).innerText = scores[index] - }) - let highest = 0 - scores.forEach(score => { - if (score > highest) highest = score - }) - bars.forEach((bar, index) => { - let width = scores[index] / highest * 100 - document.getElementById(bar).style.width = `${width}%` - if (width === 0) document.getElementById(bar).style.backgroundColor = "#171717" - }) - let categories = ["played", "won", "lost", "streak", "max"] - categories.forEach((category, index) => { - document.getElementById(category).innerText = stats[index] - }) + fillStats(stats, scores) let data = await fetch(`${window.location.href}winner`, { headers: new Headers({ "Authorization": "Bearer kRyX3RYMRY$&yEc8" @@ -275,9 +259,9 @@ async function submit(guess, real) { gg.classList.remove("input") gg.classList.add("gg") let greeting = won ? "Grazie Ragazzi!" : "Bwoah." - gg.innerHTML = `

${greeting}

The driver was

${winner.winner}!

Share

Next Stewardle

00:00:00:000

` - document.getElementsByClassName("btn")[1].onmousedown = () => { - open(document.getElementsByClassName("shareScreen")[0]) + gg.innerHTML = `

${greeting}

The driver was

${winner.winner}!

Share

Next Stewardle

00:00:00:000

` + document.getElementById("share-btn").onmousedown = () => { + open(document.getElementById("shareScreen")) if (count) { new CountUp("played", document.getElementById("played").innerText).start() new CountUp("won", document.getElementById("won").innerText).start() @@ -306,7 +290,21 @@ async function submit(guess, real) { } } }) + document.getElementById("shareScreen").innerHTML += "
\n" + + "

\n" + + "
\n" + + "

Score

\n" + + "

\n" + + "
\n" + + "
\n" + + "
Copy
\n" + + "
\n" + + "

" document.getElementById("copyable").innerHTML = clipboard + document.getElementsByClassName("btn")[0].onmousedown = () => { + pulse() + copy() + } }, 1250) } @@ -401,7 +399,7 @@ document.getElementsByClassName("close")[0].onmousedown = () => { } document.getElementsByClassName("closeShare")[0].onmousedown = () => { - close(document.getElementsByClassName("shareScreen")[0]) + close(document.getElementById("shareScreen")) } @@ -419,9 +417,8 @@ document.getElementById("highContrast-btn").onmousedown = () => { } } -document.getElementsByClassName("btn")[0].onmousedown = () => { - pulse() - copy() +document.getElementById("stats").onmousedown = () => { + open(document.getElementById("shareScreen")) } function open(element) { @@ -477,10 +474,39 @@ function copy() { navigator.clipboard.writeText(clipboard) } +function fillStats(stats, scores) { + let bars = ["one", "two", "three", "four", "five", "six"] + bars.forEach((bar, index) => { + document.getElementById(bar).innerText = scores[index] + }) + let highest = 0 + scores.forEach(score => { + if (score > highest) highest = score + }) + bars.forEach((bar, index) => { + let width = scores[index] / highest * 100 + document.getElementById(bar).style.width = `${width}%` + if (width === 0) document.getElementById(bar).style.backgroundColor = "#171717" + }) + let categories = ["played", "won", "lost", "streak", "max"] + categories.forEach((category, index) => { + document.getElementById(category).innerText = stats[index] + }) +} + document.addEventListener('DOMContentLoaded', () => { if (localStorage.getItem("highContrast") === null) { document.getElementById("highContrast").disabled = true } + if (localStorage.stats == null) { + localStorage.stats = JSON.stringify([0, 0, 0, 0, 0]) + } + let stats = JSON.parse(localStorage.stats) + if (localStorage.scores == null) { + localStorage.scores = JSON.stringify([0, 0, 0, 0, 0, 0]) + } + let scores = JSON.parse(localStorage.scores) + fillStats(stats, scores) fetch(`${window.location.href}/drivers.json`).then(res => { res.json().then(result => { driversObj = result diff --git a/views/index.ejs b/views/index.ejs index 226d175..fa0dae6 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -48,7 +48,7 @@

A new STEWARDLE will be available each day!

-
+
@@ -84,16 +84,6 @@

6

0
-
-

-
-

Score

-

-
-
-
Copy
-
-