-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathend.js
46 lines (41 loc) · 1.36 KB
/
end.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const parseUrlParameters = parameter =>
parameter
.substr(1)
.split("&")
.map(el => el.split("="))
.reduce((acc, cur) => ({ ...acc, [cur[0]]: cur[1] }), {});
const username = document.getElementById("username");
finalScore = document.getElementById("finalScore");
const mostRecentScore = localStorage.getItem("mostRecentScore");
const saveScoreBtn = document.getElementById("saveScoreButton");
const urlParams = parseUrlParameters(window.location.search);
const playAgainButton = document.getElementById("again-button");
finalScore.innerText = mostRecentScore;
playAgainButton.href = "game.html?contentId=" + urlParams.contentId;
const saveHighscore = e => {
e.preventDefault();
const rankingUrl = `https://script.google.com/macros/s/AKfycbwdGGPzI9JdH_6FN-na4boXQNZmGyv6y_690ErJc0Xhzd_CQ4A_/exec?contentId=${
urlParams.contentId
}&name=${username.value}&score=${mostRecentScore}`;
fetch(rankingUrl);
setInterval(
() =>
window.location.assign(
"highscores.html?contentId=" +
urlParams.contentId +
"&name=" +
username.value +
"&score=" +
mostRecentScore
),
0
);
};
if (urlParams.all === "1") {
username.classList.remove("hidden");
saveScoreBtn.classList.remove("hidden");
username.addEventListener(
"keyup",
() => (saveScoreBtn.disabled = !username.value)
);
}