-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
119 lines (105 loc) · 3.6 KB
/
index.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//load iframe js
var iframe = document.getElementById("iframehtml5");
var startImg = document.getElementById("start-img");
var startBtn = document.getElementById("start-btn");
var title = document.getElementById("game-title");
startImg.addEventListener("click", loadGame);
startBtn.addEventListener("click", loadGame);
function loadGame() {
iframe.src = iframe.dataset.oldsrc;
iframe.style.display = "block";
startImg.style.display = "none";
startBtn.style.display = "none";
title.style.display = "none";
gameStarted = true;
}
//mobile menu
let mobile_icon = document.querySelector(".mobile-icon");
let mobile_close_icon = document.querySelector(".mobile-close");
let mobile_menu = document.querySelector(".mobile-menu");
if (mobile_icon) {
mobile_icon.addEventListener('click', function (e) {
document.querySelector(".mobile-menu").style.right = "0";
e.stopPropagation();
})
}
if (mobile_close_icon) {
mobile_close_icon.addEventListener('click', function (e) {
document.querySelector(".mobile-menu").style.right = "-310px";
})
}
mobile_menu.addEventListener('click', function (e) {
e.stopPropagation();
})
document.addEventListener('click', function () {
document.querySelector(".mobile-menu").style.right = "-310px";
})
var gameStarted = false;
function toggleFullscreen() {
var iframe = document.getElementById("iframehtml5");
if (!document.fullscreenElement) {
if (!gameStarted) {
iframe.requestFullscreen().then(function() {
loadGame();
});
} else {
iframe.requestFullscreen();
}
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
}
}
function shareFacebook() {
const url = window.location.href;
const title = document.title;
const facebookShareUrl = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url)}"e=${encodeURIComponent(title)}`;
window.open(facebookShareUrl, "_blank");
}
function shareTwitter() {
const url = window.location.href;
const title = document.title;
const twitterShareUrl = `https://www.x.com/share?url=${encodeURIComponent(url)}&text=${encodeURIComponent(title)}`;
window.open(twitterShareUrl, "_blank");
}
function shareWhatsApp() {
const url = window.location.href;
const title = document.title;
const whatsappShareUrl = `whatsapp://send?text=${encodeURIComponent(title + " " + url)}`;
window.open(whatsappShareUrl);
}
function shareReddit() {
const url = window.location.href;
const title = document.title;
const redditShareUrl = `https://www.reddit.com/submit?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}`;
window.open(redditShareUrl, "_blank");
}
function share() {
const url = window.location.href;
const title = document.title;
if (navigator.share) {
navigator.share({
title: title,
text: title,
url: url
}).then(() => {
console.log('Successfully shared');
}).catch((error) => {
console.error('Mistakes when sharing on social media:', error);
});
} else {
const textarea = document.createElement('textarea');
textarea.value = title + "\n" + url;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
const shareButton = document.getElementById('shareButton');
shareButton.textContent = 'Copied!';
setTimeout(function() {
shareButton.textContent = 'Copy link';
}, 2000);
console.log('Copied link');
}
}