-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
144 lines (133 loc) · 4.6 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Községi Krajcár Global</title>
<link rel="icon" type="image/x-icon" href="images\favicon.ico">
</head>
<body>
<div class="cont">
<h1 id="lab">%%%Name%%% Községi Krajcár egyenlege: <br>0</h1>
</div>
<br><input type="text" name="user" id="usertxt">
<button id="send" onclick="btnclick()">Keresés</button>
</body>
<style>
body {
background-color: #ff0400;
}
h1 {
color: #fff;
text-align: center;
font-size: 6rem;
font-family: "Monaco", monospace;
opacity: 1;
animation-name: fadeInOpacity;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-duration: 0.7s;
}
.cont {
display: flex;
justify-content: center;
align-items: center;
margin: 10%;
box-sizing: content-box;
border-radius: 60px;
outline: solid 5px #fff;
}
input {
outline: solid 4px #fff;
background-color: unset;
color: #fff;
font-family: 'Century Gothic', monospace;
box-sizing: content-box;
border-radius: 2px;
outline: solid 2px #fff;
margin: 10px;
font-size: xx-large;
text-align: center;
}
button {
outline: solid 4px #fff;
background-color: unset;
color: #fff;
box-sizing: content-box;
border-radius: 10px;
outline: solid 2px #fff;
margin-bottom: 10px;
font-family: 'Century Gothic', monospace;
font-size: xx-large;
}
@keyframes fadeInOpacity {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@media screen and (max-width: 1080px) {
h1 {
font-size: 3rem;
}
}
</style>
<script type="text/javascript">
//TODO: change background color by cr ammount
function btnclick() {
//navigate to /view with the usertext input text
window.location.href = "/view?" + document.getElementById("usertxt").value;
}
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
const frst = document.getElementById('lab').innerHTML.split("<br>")[0] + "<br>";
async function refreshValue(newVal) {
newVal = parseInt(newVal);
//old inner html value
const oldVal = parseInt(document.getElementById('lab').innerHTML.replace(frst, ''));
const addVal = newVal - oldVal;
for (var i = 0; i < 60; i++) {
document.getElementById('lab').innerHTML = frst + (Math.round(addVal / 60 * i) + oldVal);
await sleep(15);
}
document.getElementById('lab').innerHTML = frst + (newVal);
}
// async function some_shit() {
// //get inner html
// var inn = document.getElementById('lab').innerHTML;
// var val = inn.split("<br>")[1];
// for (var i = 0; i < 60; i++) {
// document.getElementById('lab').innerHTML = frst + Math.round(val / 60 * i);
// await sleep(15);
// }
// document.getElementById('lab').innerHTML = inn;
// }
// some_shit();
var HOST = location.origin.replace(/^http/, 'ws') // ha http a protokoll, sima ws lesz, de ha https, simán ottmarad a plusz s a wss-hez :D
var socket = new WebSocket(HOST);
socket.addEventListener('message',(event)=>{
var data = JSON.parse(event.data);
if (data.type == 'update') {
refreshValue(data.value);
}
if (data.type == 'error') {
document.getElementById('lab').innerHTML = data.message;
}
});
socket.addEventListener('close',()=>{
if (document.URL.includes("/view")) {
location.reload();
}
});
socket.addEventListener('open',()=>{
socket.send(JSON.stringify({
type: "login",
user: "%%%Name%%%"
}));
});
refreshValue('%%%Value%%%');
</script>
</html>