-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
72 lines (63 loc) · 1.78 KB
/
script.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// global variables
var score = 0;
var clientId;
var publicKey;
// generate client ID and public key
function generateClientId() {
// instead of generating a random client ID, use the user's public key
return publicKey;
}
// get public key from user
function getPublicKey() {
// TO DO: implement public key retrieval from user
// for now, just return a dummy public key
return '0x1234567890abcdef';
}
// save score to local storage
function saveScore() {
const scoreData = {
clientId: clientId,
score: score
};
localStorage.setItem(clientId, JSON.stringify(scoreData));
}
// add score and update display
function addScore() {
score = score + 1;
saveScore();
update();
}
// update score display
function update() {
document.querySelector("#countNum").value = score;
}
// get client ID and public key
clientId = generateClientId();
publicKey = getPublicKey();
//...
// add event listener to banana button
document.querySelector("#banana-btn").addEventListener("click", addScore);
document.querySelector("#banana-btn").addEventListener("touchstart", addScore);
//...
// add event listener to banana button
document.querySelector("#banana-btn").addEventListener("click", function() {
addScore();
// Play a sound when clicked
var audio = new Audio('click_sound.mp3'); // replace with your sound file
audio.play();
// Add firework effect
const firework = document.createElement("div");
firework.className = "firework";
document.body.appendChild(firework);
setTimeout(() => {
firework.remove();
}, 1000);
});
// add event listener to window for local storage
window.addEventListener('storage', function(event) {
if (event.key === clientId) {
const storedScore = JSON.parse(localStorage.getItem(clientId)).score;
score = storedScore;
update();
}
});