-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (48 loc) · 1.78 KB
/
app.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
//HIGH SCORE
const savedData = localStorage.getItem("game");
const highScoreElement = document.querySelector(".high-score");
if(savedData){
highScoreElement.textContent = localStorage.getItem("game");
} else{
highScoreElement.textContent = 0;
}
//Intro AUDIO
document.addEventListener("DOMContentLoaded", function () {
var BoutonAudio = document.querySelector(".SoundButton");
var audio = document.querySelector("audio");
var ReplayIntro = document.querySelector(".ReplayIntro");
var StartButton = document.querySelector(".Start");
BoutonAudio.addEventListener("click", function () {
if (audio.paused) {
BoutonAudio.setAttribute("src", "img/SoundON.png");
ReplayIntro.setAttribute("hidden", "true");
audio.play();
} else {
BoutonAudio.setAttribute("src", "img/SoundOFF.png");
audio.pause();
}
});
audio.addEventListener("ended", function () {
ReplayIntro.Attribute("hidden");
});
ReplayIntro.addEventListener("click", function () {
ReplayIntro.setAttribute("hidden", "true");
BoutonAudio.setAttribute("src", "img/SoundON.png");
audio.play();
});
setTimeout(() => {
StartButton.removeAttribute("hidden");
}, 16000);
});
/////SHARE
function shareScoreFacebook() {
const gameUrl = `https://zakinane.github.io/The-Legend-Of-Crabs/`;
const quote = `I scored ${localStorage.getItem("game")} at this game!`;
const url = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(gameUrl)}"e=${encodeURIComponent(quote)}`;
window.open(url, '_blank');
}
function shareScoreX() {
const text = `I scored ${localStorage.getItem("game")} at this game! https://zakinane.github.io/The-Legend-Of-Crabs/`;
const url = `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}`;
window.open(url, '_blank');
}