-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
206 lines (170 loc) · 6.24 KB
/
index.html
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="static/img/favicon.ico">
<title>GoCorona</title>
<!-- Bootstrap core CSS -->
<link href="assets/bootstrap_css/bootstrap.min.css" rel="stylesheet">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-161601283-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-161601283-1');
</script>
<!-- Placing js here because few libraries need to load first. -->
<script src="assets/bootstrap_js/jquery-3.2.1.slim.min.js"></script>
<style type="text/css">
.main-page {
/*margin-top: 95%;*/
margin-top: 320px;
}
.new-game-text {
margin: 20px;
text-align: center;
}
#game-share-info {
margin-top: 15px;
margin-bottom: 15px;
}
html {
background: url(assets/china-bg-new.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
body {
background:none !important;
}
.game-margin {
margin: 0px 70px 0px 70px;
}
</style>
</head>
<body>
<div class="main-page" class="container-fluid">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6" style="padding: 0px;">
<div id="user-area-share" class="game-margin"></div>
<div id="user-area" class="game-margin">
<form>
<div class="form-group">
<input type="text" class="form-control" id="inputName" placeholder="Enter name" required>
</div>
<button id="create-global-game-action" type="button" class="btn btn-block btn-success">Enter Global Game</button>
<button id="create-game-action" type="button" class="btn btn-block btn-success">Create Personal Game</button>
</form>
</div>
</div>
</div>
<div class="col-md-3"></div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="assets/bootstrap_js/popper.min.js"></script>
<script src="assets/bootstrap_js/bootstrap.min.js"></script>
<script src="https://use.fontawesome.com/releases/v5.12.1/js/all.js" data-auto-replace-svg="nest"></script>
<script>
var gameLink = '';
var gameShareDOM = '<div id="game-share-info">' +
'<button id="share-url-whatsapp" type="button" class="btn btn-block btn-primary">Invite friends from Whatsapp <i class="fab fa-whatsapp"></i></button>' +
'<button id="share-url-twitter" type="button" class="btn btn-block btn-primary">Invite friends from Twitter <i class="fab fa-twitter"></i></button>' +
'<button id="share-url-clipboard" type="button" class="btn btn-block btn-primary">Copy URL to Invite <i class="fas fa-clipboard"></button>' +
'</div>';
var playGameButtonDOM = '<button id="play" type="button" class="btn btn-block btn-success" style="text-align:center;">Play</button>'
var createGameButtonsDOM = '<button id="create-global-game-action" type="button" class="btn btn-block btn-success">Enter Global Game</button>' +
'<button id="create-game-action" type="button" class="btn btn-block btn-success">Create Personal Game</button>';
$(document).ready(function () {
if(localStorage.getItem('playerName') !== null) {
$('#user-area').remove();
showGameMenu();
}
$('#create-global-game-action').on('click', function(){
if(isNameValid()){
const name = $('#inputName').val();
localStorage.setItem('playerName', name);
window.location.href = window.location.href + 'game?game_name=global_game';
}
})
$('#create-game-action').on('click', function () {
if(isNameValid()){
const name = $('#inputName').val();
localStorage.setItem('playerName', name);
showShareMenu();
}
});
$('#user-area-share').on('click', function(e){
if(e.target.id === "share-url-whatsapp"){
let whatsAppText = "Don't join it if you are easily addicted to games: " + gameLink
let whatsAppLink = 'https://wa.me/?text=' + encodeURI(whatsAppText)
window.open(whatsAppLink)
}
if(e.target.id === "share-url-twitter"){
let twitterText = "Don't join it if you are easily addicted to games: " + gameLink
let twitterLink = 'https://twitter.com/intent/tweet?text=' + encodeURI(twitterText)
window.open(twitterLink)
}
if(e.target.id === "share-url-clipboard"){
copyToClipboard(gameLink);
alert("Link copied successfully!")
}
if(e.target.id === "play"){
window.location.href = gameLink;
}
if(e.target.id === "create-global-game-action"){
window.location.href = window.location.href + 'game?game_name=global_game';
}
if(e.target.id === "create-game-action"){
showShareMenu();
}
})
});
function showGameMenu(){
$('#user-area-share').append(createGameButtonsDOM);
}
function showShareMenu() {
const randomId = generateRandomId(6);
gameLink = window.location.href + 'game?game_name=' + randomId;
//unmount existing DOM
$('#user-area').remove();
//mount share option DOM
$('#user-area-share').append(gameShareDOM);
$('#user-area-share').append(playGameButtonDOM);
$('#game-link').text(gameLink);
}
function isNameValid(){
const name = $('#inputName').val()
if(name.length < 3){
alert("Please enter name greater then three characters.")
return false;
}
if(name.length > 20){
alert("Your name should not exceed 20 characters.")
return false;
}
return true;
}
function generateRandomId(idLength) {
let r = Math.random().toString(36).substring(idLength);
return r;
}
function copyToClipboard(text) {
var dummy = document.createElement("textarea");
document.body.appendChild(dummy);
dummy.value = text;
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
}
</script>
</body>
</html>