/
device_html.go
222 lines (190 loc) · 5.98 KB
/
device_html.go
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
package http
const DEVICE_HTML_CONTENT = `
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DT - DEVICES</title>
<style>
@import url(https://fonts.googleapis.com/css?family=Roboto:400,300,100,500,700,900);
html,
body {
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
}
body {
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(135deg, #2c2d30 0%, #353535 100%);
width: 100%;
height: 100vh;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
margin: 1rem;
border-radius: 50px;
border: none;
background: rgb(39, 39, 39);
width: 300px;
padding: 30px;
box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
}
.container h1 {
color: #FFF;
font-size: 1.5rem;
margin-bottom: 5px;
}
.container .connectionsArea h4 {
color: #FFF;
font-size: 1rem;
margin-bottom: 20px;
}
.connectionsArea {
display: flex;
align-items: center;
gap: 5px;
}
.container-count {
color: #FFF;
background: #363636;
padding: 0.3rem;
border-radius: 50%;
font-size: 1em;
display: flex;
align-items: center;
justify-content: center;
}
.devices {
display: flex;
flex-direction: column;
width: 80%;
}
.search {
padding: 10px;
background: #2c2d30;
outline: none;
border: 0;
border-radius: 10px;
color: #FFF;
}
.device-id-list {
margin-top: 10px;
display: flex;
flex-direction: column;
gap: 5px;
padding: 5px;
border-radius: 10px;
border: #2b2c359d solid 2px;
height: 200px;
overflow-y: scroll;
}
.device-id-list::-webkit-scrollbar {
display: none;
}
.device-id {
background: #2c2d30;
border-radius: 10px;
color: #FFF;
font-size: 13px;
text-align: center;
padding: 5px;
font-family: "Roboto", sans-serif;
}
.device-id-not-found {
display: none;
text-align: center;
margin: 10px 0;
color: #ff0000;
background: #2c2d30;
border-radius: 10px;
padding: 5px;
font-family: "Roboto", sans-serif;
}
</style>
</head>
<body>
<div class="container">
<h1>CHECKUSER - @DuTra01</h1>
<div class="connectionsArea">
<h4>TOTAL DE DEVICE ID</h4>
<div class="container-count">
<span id="total">00</span>
</div>
</div>
<div class="devices">
<input type="text" class="search" placeholder="Digite um nome...">
<div class="device-id-list"></div>
<div class="device-id-not-found">
Dispositivos não encontrados!
</div>
</div>
</div>
<script>
let timeout = null
const deviceListElement = document.querySelector('.device-id-list')
const search = document.querySelector('.search')
const devicesNotFoundElement = document.querySelector('.device-id-not-found')
const createDeviceIDElement = deviceID => {
const element = document.createElement('span')
element.className = 'device-id'
element.innerHTML = deviceID
return element
}
const appendDeviceIDElementInList = element => deviceListElement.appendChild(element)
const cleanDeviceListElement = () => deviceListElement.innerHTML = ''
const showDevicesNotFound = () => {
devicesNotFoundElement.style.display = 'block'
deviceListElement.style.display = 'none'
}
const hideDevicesNotFound = () => {
deviceListElement.style.display = 'flex'
devicesNotFoundElement.style.display = 'none'
}
const searchHandler = value => setTimeout(async () => {
if (!value) {
showDevices()
return
}
const url = "/devices/list/" + value
const data = await fetch(url).then(r => r.json())
if (!Array.isArray(data) || data.length == 0) {
showDevicesNotFound()
return
}
hideDevicesNotFound()
cleanDeviceListElement()
data.forEach(device => {
const element = createDeviceIDElement(device)
appendDeviceIDElementInList(element)
})
}, 500)
search.addEventListener('keyup', e => {
clearTimeout(timeout)
timeout = searchHandler(e.target.value)
})
const showDevices = async () => {
const url = '/devices/list'
const data = await fetch(url).then(e => e.json())
hideDevicesNotFound()
cleanDeviceListElement()
data.forEach(device => {
const element = createDeviceIDElement(device.username + " - " + device.id)
appendDeviceIDElementInList(element)
})
}
showDevices()
const main = async () => {
const url = '/devices/count'
const data = await fetch(url).then(e => e.json())
document.querySelector('#total').innerHTML = data.count.toString().padStart(2, '0')
}
main()
</script>
</body>
</html>
`