-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (49 loc) · 1.57 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
document.addEventListener('DOMContentLoaded', function () {
createElement()
}, false);
function replaceMe(html, data) {
const pattern = /:\s*(\w+?)\s*:/g;
return html.replace(pattern, (_, token) => data[token] || '');
}
function generateRandomNumbers() {
let generatedNumbers = []
let number = 0
let index = 1
while (index < 16) {
number = Math.floor((Math.random() * 25) + 1)
if (generatedNumbers.includes(number)) {
continue
}
generatedNumbers.push(number)
index++
}
return generatedNumbers
}
function createElement() {
const html = `<label id="number-:number:">:number:</label>
`
let data = {number: ''}
let divAppendNumbers = document.getElementById('div-append-numbers');
let index = 1
while (index < 26) {
data.number = index > 9 ? index : `0${index}`
let singleTmp = replaceMe(html, data)
index++
let spam = document.createElement("span")
spam.innerHTML = singleTmp
divAppendNumbers.appendChild(spam)
}
}
function generateNewBet() {
document.querySelectorAll('.selected').forEach(el => el.classList.remove('selected'))
let generateNumbers = generateRandomNumbers().sort((a, b) => a-b)
let index = 0
while (index < generateNumbers.length) {
let id = generateNumbers[index] > 9 ? `number-${generateNumbers[index]}`
: `number-0${generateNumbers[index]}`
if (document.getElementById(id)) {
document.getElementById(id).classList.add('selected')
}
index ++
}
}