-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
337 lines (274 loc) Β· 7.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Play online slot machine and win cons!">
<title>Roll!</title>
<script src="//psaunsooksuthi.com/vignette.min.js" data-zone="8257405" data-sdk="show_8257405"></script>
<style>
html, body {
height: 100%;
}
body {
margin: 0;
background: #eee;
display: flex;
justify-content: center;
align-items: center;
user-select: none;
}
@keyframes show {
from { margin-top: -64px; }
to { margin-top: 0; }
}
@keyframes tilt-shaking {
0% { transform: rotate(0deg); }
25% { transform: rotate(3deg); }
50% { transform: rotate(0eg); }
75% { transform: rotate(-3deg); }
100% { transform: rotate(0deg); }
}
.tada, .balance {
width: 192px;
height: 64px;
font: bold 24px/64px monospace;
text-align: center;
border: 1px solid #eee;
box-sizing: border-box;
}
.balance {
background: #3b5dc9;
color: #fff;
}
.balance:before {
content: 'πͺ';
margin-right: 10px;
}
.rows {
width: 192px;
height: 192px;
display: flex;
}
.row {
width: 64px;
height: 192px;
overflow: hidden;
}
.item {
width: 64px;
height: 64px;
animation-duration: 0.7s;
animation-name: show;
text-align: center;
overflow: hidden;
font: 24px/64px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
border: 1px solid #eee;
box-sizing: border-box;
background: #fff;
transition: all 0.2s ease 0s;
}
button {
margin: 0;
padding: 0;
width: 192px;
height: 64px;
display: block;
background: #38b764;
color: #fff;
text-transform: uppercase;
letter-spacing: 5px;
transition: all 0.3s ease 0s;
border: 1px solid #fff;
box-sizing: border-box;
font: bold 24px/32px monospace;
opacity: 1;
}
.spin_button {
animation: tilt-shaking 0.2s infinite;
}
.hidden {
opacity: 0;
pointer-events: none;
}
button:disabled {
background: #b13e53;
color: rgba(255, 255, 255, 0.5);
animation: none;
}
.watch_ads {
position: absolute;
bottom: 1px;
left: 50%;
transform: translateX(-50%);
font-size: 14px;
letter-spacing: 0;
}
</style>
</head>
<body>
<div class="container">
<div class="tada hidden">π π π</div>
<div class="balance">0</div>
<div class="rows">
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
</div>
<button class="spin_button">roll</button>
<button class="restart_button hidden">restart</button>
</div>
<script type="text/javascript">
const sessionId = Math.random().toString(36).slice(2)
const variations = ['π', 'π', 'π', 'π²', 'π', 'π', 'π', 'π', 'π']
const rows = [].slice.call(document.querySelectorAll('.row'));
const timeout = (time) => new Promise((resolve) => setTimeout(resolve, time))
const addItem = (row) => {
const variationId = Math.floor(Math.random() * variations.length)
const i = document.createElement('div')
i.classList.add('item')
i.innerText = variations[variationId]
row.insertBefore(i, row.firstChild)
}
const initRows = () => {
rows.forEach(row => {
Array.from({ length: 3 }).forEach(() => addItem(row))
})
}
const rollAndFill = async () => {
for (let i = 0; i < 30; i++) {
if (i < 10) {
addItem(rows[0])
}
if (i < 20) {
addItem(rows[1])
}
addItem(rows[2])
await timeout(80)
}
}
const removeOldItems = () => {
rows.forEach((row) => {
const items = row.querySelectorAll('.item')
const toRemove = [].slice.call(items, 3) // remove all except 3 first items
toRemove.forEach((item) => item.parentNode.removeChild(item))
})
}
const checkAndHighlight = (item1, item2, item3) => {
if (item1.innerText === item2.innerText && item1.innerText === item3.innerText) {
item1.style.background = '#38b764'
item2.style.background = '#38b764'
item3.style.background = '#38b764'
return true
}
return false
}
const getBalance = () => {
return parseInt(document.querySelector('.balance').innerText.trim(), 10)
}
const updateBalance = (diff) => {
document.querySelector('.balance').innerText = getBalance() + diff;
}
const updateBalanceByOne = async (diff) => {
if (diff < 1) {
return
}
await timeout(1000)
while (diff > 0) {
if (diff > 100) {
updateBalance(100)
diff -= 100
} else if (diff > 10) {
updateBalance(10)
diff -= 10
} else {
updateBalance(1)
diff -= 1
}
await timeout(100)
}
updateButtons()
}
const updateButtons = () => {
const spinButton = document.querySelector('.spin_button')
const restartButton = document.querySelector('.restart_button')
console.log('update buttons')
if (getBalance() > 0) {
spinButton.removeAttribute('disabled')
spinButton.innerText = 'roll'
if (!restartButton.classList.contains('hidden')) {
restartButton.classList.add('hidden')
}
} else {
spinButton.innerText = 'bankrupt'
restartButton.classList.remove('hidden')
}
}
const checkWinning = async () => {
const items = rows.map((row) => [].slice.call(row.querySelectorAll('.item')))
const checks = [
// horizontal
checkAndHighlight(items[0][0], items[0][1], items[0][2]),
checkAndHighlight(items[1][0], items[1][1], items[1][2]),
checkAndHighlight(items[2][0], items[2][1], items[2][2]),
// vertical
checkAndHighlight(items[0][0], items[1][0], items[2][0]),
checkAndHighlight(items[0][1], items[1][1], items[2][1]),
checkAndHighlight(items[0][2], items[1][2], items[2][2]),
// diagonal
checkAndHighlight(items[0][0], items[1][1], items[2][2]),
checkAndHighlight(items[2][0], items[1][1], items[0][2]),
]
const wins = checks.filter((i) => i)
if (wins.length > 0) {
const amount = (6 + wins.length) * wins.length
document.querySelector('.tada').classList.remove('hidden')
await timeout(500)
await updateBalanceByOne(amount)
document.querySelector('.tada').classList.add('hidden')
}
updateButtons()
}
document.querySelector('.spin_button').addEventListener('click', async () => {
document.querySelector('.spin_button').setAttribute('disabled', 'disabled')
updateBalance(-1)
await rollAndFill()
await timeout(500)
removeOldItems()
await checkWinning()
})
document.querySelector('.restart_button').addEventListener('click', () => {
window.location.reload()
})
initRows()
updateBalanceByOne(5)
try {
const button = document.body.appendChild(document.createElement('button'))
button.classList.add('watch_ads')
button.innerText = 'Watch Ads (+15πͺ)'
const refresh = () => {
// button is inactive until the ad is loaded
button.setAttribute('disabled', 'disabled')
show_8257405('preload').then(() => {
// the ad is ready, the button is active
button.removeAttribute('disabled')
}).catch(e => console.error(e))
}
// start ad preloading
refresh()
button.addEventListener('click', () => {
show_8257405().then(() => {
// add 15 coins after the user has watched an ad
updateBalanceByOne(15)
// preloading ad again
refresh()
}).catch(e => {
console.error(e)
alert('Sorry, no ads this time!')
})
})
} catch (e) {}
</script>
</body>
</html>