-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathindex.html
More file actions
414 lines (371 loc) · 14.6 KB
/
index.html
File metadata and controls
414 lines (371 loc) · 14.6 KB
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script async src="https://www.googletagmanager.com/gtag/js?id=G-5899C1DJM0"></script>
<script defer src="https://umami.lazygyu.net/script.js" data-website-id="205aee0d-30b6-4c69-a053-0c72c8377be0"></script>
<title>Marble Roulette</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="apple-touch-icon" sizes="57x57" href="assets/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="assets/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="assets/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="assets/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="assets/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="assets/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="assets/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="assets/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="assets/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="assets/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="assets/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="assets/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="assets/favicon-16x16.png">
<link rel="manifest" href="assets/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="assets/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<meta name="description" content="A lucky draw by dropping marbles, made by lazygyu">
<meta property="og:url" content="https://lazygyu.github.io/roulette/">
<meta property="og:title" content="Marble Roulette">
<meta property="og:description" content="A lucky draw by dropping marbles, made by lazygyu">
<meta property="og:site_name" content="lazygyu.github.io">
<meta property="og:type" content="website">
<link rel='stylesheet' href='assets/style.scss' />
</head>
<body>
<script type="module" src="./src/index.ts"></script>
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-5899C1DJM0');
function getNames() {
const value = document.querySelector('#in_names').value.trim();
return value.split(/[,\r\n]/g).map(v => v.trim()).filter(v => !!v);
}
function parseName(nameStr) {
const weightRegex = /(\/\d+)/;
const countRegex = /(\*\d+)/;
const hasWeight = weightRegex.test(nameStr);
const hasCount = countRegex.test(nameStr);
const name = /^\s*([^\/*]+)?/.exec(nameStr)[1];
const weight = hasWeight ? parseInt(weightRegex.exec(nameStr)[1].replace('/', '')) : 1;
const count = hasCount ? parseInt(countRegex.exec(nameStr)[1].replace('*', '')) : 1;
return {
name,
weight,
count,
};
}
function getReady() {
const names = getNames();
window.roulette.setMarbles(names);
ready = names.length > 0;
localStorage.setItem('mbr_names', names.join(','));
switch (winnerType) {
case 'first':
setWinnerRank(1);
break;
case 'last':
const total = window.roulette.getCount();
setWinnerRank(total);
break;
}
}
function setWinnerRank(rank) {
document.querySelector('#in_winningRank').value = rank;
window.options.winningRank = rank - 1;
window.roulette.setWinningRank(window.options.winningRank);
if (winnerType === 'first') {
document.querySelector('.btn-first-winner').classList.toggle('active', true);
document.querySelector('.btn-last-winner').classList.toggle('active', false);
document.querySelector('#in_winningRank').classList.toggle('active', false);
} else if (winnerType === 'last') {
document.querySelector('.btn-first-winner').classList.toggle('active', false);
document.querySelector('.btn-last-winner').classList.toggle('active', true);
document.querySelector('#in_winningRank').classList.toggle('active', false);
} else if (winnerType === 'custom') {
document.querySelector('.btn-first-winner').classList.toggle('active', false);
document.querySelector('.btn-last-winner').classList.toggle('active', false);
document.querySelector('#in_winningRank').classList.toggle('active', true);
}
}
let ready = false;
let winnerType = 'first';
document.addEventListener('DOMContentLoaded', () => {
initialize();
});
function initialize() {
if (!window.roulette || !window.roulette.isReady) {
console.log('does not loaded yet');
setTimeout(initialize, 100);
return;
}
console.log('initializing start');
const urlParams = new URLSearchParams(window.location.search);
const namesFromUrl = urlParams.get('names');
if (namesFromUrl) {
document.querySelector('#in_names').value = namesFromUrl.replace(/,/g, '\n');
} else {
const savedNames = localStorage.getItem('mbr_names');
if (savedNames) {
document.querySelector('#in_names').value = savedNames;
}
}
document.querySelector('#in_names').addEventListener('input', () => {
getReady();
});
document.querySelector('#in_names').addEventListener('blur', () => {
const nameSource = getNames();
const nameSet = new Set();
const nameCounts = {};
nameSource.forEach(nameSrc => {
const name = parseName(nameSrc);
const key = name.weight > 1 ? `${name.name}/${name.weight}` : name.name;
if (!nameSet.has(key)) {
nameSet.add(key);
nameCounts[key] = 0;
}
nameCounts[key] += name.count;
});
const result = [];
Object.keys(nameCounts).forEach(key => {
if (nameCounts[key] > 1) {
result.push(`${key}*${nameCounts[key]}`);
} else {
result.push(key);
}
});
const oldValue = document.querySelector('#in_names').value;
const newValue = result.join(',');
if (oldValue !== newValue) {
document.querySelector('#in_names').value = newValue;
getReady();
}
});
document.querySelector('#btnShuffle').addEventListener('click', () => {
getReady();
});
document.querySelector('#btnStart').addEventListener('click', () => {
if (!ready) return;
gtag && gtag('event', 'start', {
'event_category': 'roulette',
'event_label': 'start',
'value': window.roulette.getCount(),
});
const names = getNames();
const marbles = names.map(n => {
const p = parseName(n);
return { name: p.name, count: p.count };
});
if (typeof umami !== 'undefined') {
umami.track('start', { count: window.roulette.getCount() });
marbles.forEach(m => {
umami.track('marble', { name: m.name, count: m.count });
});
}
window.roulette.start();
document.querySelector('#settings').classList.add('hide');
document.querySelector('#donate').classList.add('hide');
});
document.querySelector('#chkAutoRecording').addEventListener('change', (e) => {
window.options.autoRecording = e.target.matches(':checked');
window.roulette.setAutoRecording(window.options.autoRecording);
});
document.querySelector('#chkSkill').addEventListener('change', (e) => {
window.options.useSkills = e.target.matches(':checked');
window.roulette.setWinningRank(window.options.winningRank);
});
document.querySelector('#chkDarkMode').addEventListener('change', (e) => {
window.options.darkMode = e.target.matches(':checked');
window.roulette.setTheme(window.options.darkMode ? 'dark' : 'light');
document.documentElement.classList.toggle('light', !window.options.darkMode);
});
document.querySelector('#in_winningRank').addEventListener('change', (e) => {
const v = parseInt(e.target.value, 10);
winnerType = 'custom';
setWinnerRank(isNaN(v) ? 0 : v);
});
document.querySelector('.btn-last-winner').addEventListener('click', () => {
const total = window.roulette.getCount();
winnerType = 'last';
setWinnerRank(total);
});
document.querySelector('.btn-first-winner').addEventListener('click', () => {
winnerType = 'first';
setWinnerRank(1);
});
window.roulette.addEventListener('goal', () => {
ready = false;
setTimeout(() => {
document.querySelector('#settings').classList.remove('hide');
document.querySelector('#donate').classList.remove('hide');
}, 3000);
});
window.roulette.addEventListener('message', (e) => {
simpleToast(e.detail);
});
const toggleBtn = document.querySelector('#btnToggleSettings');
const collapsible = document.querySelector('.collapsible-rows');
toggleBtn.addEventListener('click', () => {
collapsible.classList.toggle('collapsed');
toggleBtn.querySelector('.toggle-arrow').textContent =
collapsible.classList.contains('collapsed') ? '▲' : '▼';
});
document.querySelector('#btnShuffle').click();
const maps = window.roulette.getMaps();
const mapSelector = document.querySelector('#sltMap');
maps.forEach((map) => {
const option = document.createElement('option');
option.value = map.index;
option.innerHTML = map.title;
option.setAttribute('data-trans', '');
window.translateElement(option);
mapSelector.append(option);
});
mapSelector.addEventListener('change', (e) => {
const index = e.target.value;
window.roulette.setMap(index);
});
// const checkDonateButtonLoaded = () => {
// const btn = document.querySelector('span.bmc-btn-text');
// if (!btn) {
// setTimeout(checkDonateButtonLoaded, 100);
// } else {
// console.log('donation button has been loaded');
// btn.setAttribute('data-trans', '');
// window.translateElement(btn);
// }
// };
// setTimeout(checkDonateButtonLoaded, 100);
const currentNotice = 5;
const noticeKey = 'lastViewedNotification';
const closeNotice = () => {
document.querySelector('#notice').style.display = 'none';
localStorage.setItem(noticeKey, currentNotice.toString());
};
const openNotice = () => {
console.log('openNotice');
document.querySelector('#notice').style.display = 'flex';
};
document.querySelector('#closeNotice').addEventListener('click', () => {
closeNotice();
});
document.querySelector('#btnNotice').addEventListener('click', () => {
openNotice();
});
function simpleToast(msg) {
const toast = document.createElement('div');
toast.classList.add('toast');
toast.innerHTML = msg;
if (window.translateElement) {
console.log('try to translate');
window.translateElement(toast);
}
document.body.appendChild(toast);
setTimeout(() => {
document.body.removeChild(toast);
}, 1200);
}
const checkNotice = () => {
const lastViewed = localStorage.getItem(noticeKey);
console.log('lastViewed', lastViewed);
if (lastViewed === null || Number(lastViewed) < currentNotice) {
openNotice();
}
};
checkNotice();
}
</script>
<div id="settings" class="settings">
<div class="right">
<button id="btnToggleSettings" class="btn-toggle-settings">
<span data-trans>Settings</span>
<i class="toggle-arrow">▲</i>
</button>
<div class="collapsible-rows collapsed">
<div class="row">
<label for='sltMap'>
<i class="icon map"></i>
<span data-trans>Map</span>
</label>
<select id="sltMap"></select>
</div>
<div class="row row-toggles">
<div class='toggle-item'>
<label for='chkAutoRecording'>
<i class="icon record"></i>
<span data-trans>Recording</span>
</label>
<input type="checkbox" id="chkAutoRecording" />
</div>
<div class='toggle-item'>
<label for='chkSkill'>
<i class="icon bomb"></i>
<span data-trans>Using skills</span>
</label>
<input type="checkbox" id="chkSkill" checked />
</div>
</div>
<div class="row">
<label>
<i class="icon trophy"></i>
<span data-trans>The winner is</span>
</label>
<div class="btn-group">
<button class="btn-winner btn-first-winner active" data-trans>First</button>
<button class="btn-winner btn-last-winner" data-trans>Last</button>
<input type="number" id="in_winningRank" value="1" min="1" />
</div>
</div>
<div class="row row-theme">
<div class='theme'>
<i class='icon sun'></i>
<input type='checkbox' id='chkDarkMode' checked />
<i class='icon moon'></i>
</div>
</div>
</div>
</div>
<div class="left">
<h3 data-trans>Enter names below</h3>
<textarea id="in_names" placeholder="Input names separated by commas or line feed here" data-trans="placeholder">수박*2,키위*2,귤*2</textarea>
<div class="actions">
<button id="btnNotice">
<i class="icon megaphone"></i>
</button>
<a href='https://marblerouletteshop.com' target='_blank' id="btnShop" class='btn new' title='MarbleRoulette Shop'>
<img src='assets/images/marblerouletteshop.png' />
</a>
<div class="sep"></div>
<button id="btnShuffle">
<i class="icon shuffle"></i>
<span data-trans>Shuffle</span>
</button>
<button id="btnStart">
<i class="icon play"></i>
<span data-trans>Start</span>
</button>
</div>
</div>
</div>
<div id="notice">
<h1>Notice</h1>
<div class="notice-body">
<h2>커스텀 룰렛 기능 오픈!</h2>
<p>나만의 특별한 룰렛을 만들 수 있는 커스텀 룰렛 기능이 오픈했어요!</p>
<p>
<a href='https://marblerouletteshop.com/intro/roulette' target='_blank' class='shop-button holographic'><img
src='assets/images/marblerouletteshop.png' width='125' height='125' /> 룰렛 꾸미러 가기</a>
</p>
</div>
<div class="notice-action">
<button id="closeNotice" data-trans>Close</button>
</div>
</div>
<div class="copyright">© 2022-2026.<a href="https://lazygyu.net" target="_blank">lazygyu</a> <span data-trans>This program is freeware and may be used freely anywhere, including in broadcasts and videos.</span>
</div>
</body>
</html>