-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathex.html
More file actions
388 lines (358 loc) · 14.1 KB
/
ex.html
File metadata and controls
388 lines (358 loc) · 14.1 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
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8"/>
<title>block explorer golos.io</title>
<meta name="Description" content="block explorer для голоса - golos.io история пользователей голоса в реальном времени">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style>
/* https://golos.io/@vik */
body {
max-width: 100%;
overflow-x: hidden;
font-family: Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
background: #2b2b2b url(https://upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Procaterol.svg/200px-Procaterol.svg.png);
background-position: center;
transition: 1s all ease;
background-attachment: fixed;
}
body:hover {
background-position: left;
}
body::-webkit-scrollbar,
.scrl::-webkit-scrollbar{
width:7px;height:9px
}
body::-webkit-scrollbar-track,
.scrl::-webkit-scrollbar-track{
background:#053363
}
body::-webkit-scrollbar-thumb,
.scrl::-webkit-scrollbar-thumb{
background:rgba(255,255,255,.4)
}
h1 {
color: #ffffff;
text-align: center;
text-transform: uppercase;
margin: 10px 0 0 0;
font-size: 5em;
text-shadow: 1px 3px 40px #22035a;
}
img {
max-width: 100%;
height: auto;
}
#blockexplr {
text-align: center;
font-size: 2rem;
color: #ffd121;
text-shadow: 1px 1px 6px black;
}
#sila {
display: block;
color: white;
text-align: center;
padding: 10px;
border-radius: 3px;
font-weight: 700;
}
#nicedata {
position:relative;
max-width: 960px;
width: 50%;
float: left;
}
#nicedata #item{
transition:1s all ease;
transform:translate3d(0px, -100px, 0px);
position:absolute;
opacity:0;
}
#nicedata #item.anim{
transform:translate3d(0px, 0px, 0px);
opacity:1;
transition:1s all ease;
position:relative;
}
header {
background: #0d0d0d url(https://s27.postimg.org/kj0ro3zcz/d941c938a01d450288d87fdba4e66af176f62c50_m.gif) no-repeat center;
text-align:center;
color: white;
margin: 0;
padding: 15px;
box-shadow: 0 0 20px black;
}
#result {
float:right;
width:50%;
position:relative;
font-size:8pt;
margin: 55px auto;
}
.static {
text-align: center;
margin-bottom: 25px;
}
#result #item {
background: black;
color: white;
padding: 5px;
line-height: 1;
margin: 10px 5px 0;
}
.myJson span {
background: #315d9e;
color: white;
border-radius: 3px;
padding: 1px 8px;
font-weight: 700;
}
.myJson {
background: #ffffff;
padding: 15px;
word-break: break-word;
color: #636363;
border-radius: 3px;
margin: 40px 15px 0;
box-shadow: 0 0 15px black;
transition: 1s all ease;
}
#witness a {
color: white;
padding: 4px 10px;
border-radius: 10px;
text-decoration: none;
font-weight: 700;
}
#nicedata {
max-width: 960px;
margin: 25px auto;
}
.myJson a {
text-decoration: none;
color: white;
background: #18d47e;
border-radius: 3px;
padding: 5px 10px;
font-weight: 700;
box-shadow: 0 0 10px -5px black;
text-transform: capitalize;
vertical-align: middle;
}
.textpost {
background: rgba(0, 0, 0, 0.42);
padding: 4px 15px;
margin: 2px 15px 0;
max-height: 100px;
border-radius: 3px;
color: #ffffff;
font-size: .8rem;
overflow: auto;
}
.textpost h4 {
margin: 0 0 3px 0;
}
.alert {
background: #ff4343;
color: white;
padding: 20px;
margin: 15px;
text-align: center;
box-shadow: 0 0 20px black;
border-radius: 3px;
font-size: 16px;
}
input[type="number"] {
border: 0;
font-size:1.3rem;
height:45px;
min-width: 200px;
border-radius: 3px;
box-shadow: inset 0 0px 5px 0px black;
background: rgba(130, 130, 130, 0.48);
color: white;
padding: 0 15px;
}
button {
background: #1ba77b;
box-shadow: 0 0 10px black;
border: 0;
height:45px;
font-weight: 700;
color: white;
padding: 10px;
border-radius: 3px;
font-size:1.3rem;
}
@media screen and (max-width: 700px) {
h1 {
font-size: 2em;
}
#blockexplr {
font-size: 1.5em;
}
#nicedata, #result {
width: 100%!important;
float: none!important;
}
button {
display: block;
margin: 10px auto;
}
}
</style>
</head>
<body>
<header>
<h1>ws.golos.io</h1>
<h2 id="blockexplr">Вычисление последнего блока... </h2>
<div class="static">
<input id="blockexplorer" type="number" name="quantity" min="1"><button onClick="searchBlock()">Задать стартовый блок</button>
</div>
<span id="witness">Выбираем ноду... </span>
<span id="merkle">Определяем id блока...</span>
<article>Это тестовая страница, вы можете забрать исходники или почитать как сделать такую же <a href="https://golos.io/@vik/">golos.io/@vik</a></article>
</header>
<div id="nicedata"></div><div id="result"></div>
<script>
// Объявляем переменные
var socket = new WebSocket('wss://ws.golos.io'),
lastblock, startblock;
// Открываем сокет
function connectGolos() {
socket.onopen = function(event) {
// Выставляем интервал в 3000 ms
setInterval(function() {
socket.send(JSON.stringify({ // Отправляем запрос
id: 1,
method: 'get_dynamic_global_properties', // Запрашиваем конкретно эти данные
'params': []
}));
lastblock++; // Увеличиваем на 1 значение данной переменной при каждом выполнении функции (каждые 3 секунды)
}, 3000);
}};
fixblock = true; // Устанавливаем для переменной булево значение - ВКЛ
function searchBlock() {
var inputblock = document.getElementById("blockexplorer");
var blocknum = inputblock.value;
lastblock = blocknum;
fixblock = false;
connectGolos();
}
function itemShow(){setTimeout(function() {
document.getElementById("item").classList.add('anim');
}, 200); }
socket.onmessage = function(event) {
var silaGolosa, powerMovement,
data = JSON.parse(event.data); // Полученные данные парсим в формат JSON
merkle = data.result.transaction_merkle_root;
if (fixblock) { // Выполнять если fixblock = true (мы указали это за пределами onmessage)
startblock = data.result.last_irreversible_block_num; // Получаем номер блока и записываем в переменную
lastblock = startblock; // записываем в переменную номер начального блока
fixblock = false; //теперь переводим условие в false, и мы больше не сможем менять номер начального блока
}
if (data.id === 1 ) { // Если ответ на наш socket.send id 1
movementTotal = data.result.total_vesting_shares.split(' ')[0]; /// Движения силы
silaTotal = data.result.total_vesting_fund_steem.split(' ')[0]; /// Общее количество силы
socket.send(JSON.stringify({ // Отправляем запрос на получение аккаунта
id: 2,
method: 'get_accounts',
params: [
['vik'] // запрашиваем данные на ник (не обязательно пока, понадобится в другой ситуации)
]
}));
socket.send(JSON.stringify({
id: 3,
method: 'get_block',
'params': [lastblock]// Отправляем запрос на получение текущего блока
}));
document.getElementById('blockexplr').innerHTML = ('Исследуемый блок ' + lastblock);
}
if (data.id === 2) {
powerMovement = data.result[0].vesting_shares.split(' ')[0];
silaGolosa = silaTotal * (powerMovement / movementTotal);
// document.getElementById('sila').innerHTML = ('Ваша сила голоса <span>' + silaGolosa + '</span>');
}
if (data.id === 3 && merkle !== "0000000000000000000000000000000000000000"){ // Если данные ответа на запрос с id = 3
itemShow();
var fulldata = JSON.stringify(data.result);
document.getElementById('result').insertAdjacentHTML('afterbegin', '<div id="item" class="myJson fulldata">' + fulldata + '</div>');
$witness = data.result.witness;
$timestamp = data.result.timestamp;
document.getElementById('merkle').innerHTML = ('id <span>' + merkle + '</span> Время блока ' + $timestamp);
document.getElementById('witness').innerHTML = ('Делегат <a href="https://golos.io/@' + $witness + '">@' + $witness + '</a>');
tx = data.result.transactions[0].operations[0][1]; // Сокращенный путь до данные> транзакции> операции>
trigger = data.result.transactions[0].operations[0][0]; // Тригер. Определяем коммент, голос, подписку и другое
$voter = tx.voter; // Переменная с именем голосующего
$power = tx.weight; // Переменная с силой голоса при голосе
$author = tx.author; // Автор. Одна переменная на многие виды операций
$permlink = tx.permlink; // Ссылка. Так же есть в многих операциях
$parent = tx.parent_author; // Автор - родитель поста. Учавствует в комментах
$body = tx.body; // Тело коммента или поста
$title = tx.title; // Заголовок поста, в комментах пуст
if (trigger == 'vote'){ // Если триггер голос
votehtml = '<div id="item" class="myJson"><b>'+$voter+'</b> голосует за <span>'+$author+'</span>. Сила '+$power+' </div>'
document.getElementById('nicedata').insertAdjacentHTML('afterbegin',votehtml); // Вставляем данные на страницу
}
if (trigger == 'comment'){ // Если триггер коммент
if ($parent !== ""){ // Если родитель поста не пустое место :)
commthtml = '<div id="item" class="myJson">'+$author+' комментирует '+$parent+': '+$body+' </div>'
document.getElementById('nicedata').insertAdjacentHTML('afterbegin',commthtml); // Вставляем html на страницу
} else { // А если автор-родитель пуст, то вставим html заточенный под пост, а не комментарии.
posthtml = '<div id="item" class="myJson">'+$author+' разместил пост <h4>'+$title+'</h4>'+$body+'</div>'
document.getElementById('nicedata').insertAdjacentHTML('afterbegin',posthtml);
}
}
if (trigger == 'custom_json'){ // Если триггер custom_json (обычно это фолловинг)
var follow = JSON.parse(tx.json)[1], // Получаем данные свойства json внутри custom_json
$follower = follow.follower, // Находим имя фолловера
$followin = follow.following; // Находим имя, на кого подписался фолловер
// Придумываем оформление вывода фолловинга
follhtml = '<div id="item" class="myJson"><span>'+$follower+'</span> подписка на <b>'+$followin+'</b></div>'
document.getElementById('nicedata').insertAdjacentHTML('afterbegin',follhtml);
}
if (trigger == 'transfer'){ // Если триггер трансфер
var $amount = tx.amount,
$from = tx.from,
$memo = tx.memo,
$to = tx.to;
transfhtml = '<div id="item" class="myJson"><b>'+$from+'</b> отправил '+$amount+' <span>'+$to+'</span>\
<p><i>'+$memo+'</i></p></div>'
document.getElementById('nicedata').insertAdjacentHTML('afterbegin',transfhtml);
}
if (trigger == 'feed_publish'){
var $publisher = tx.publisher,
$base = tx.exchange_rate.base,
$quote = tx.exchange_rate.quote;
feedhtml = '<div id="item" class="myJson">Прайс фид от <span>'+$publisher+'</span>: '+$base+' = <b>'+$quote+'</b> </div>';
document.getElementById('nicedata').insertAdjacentHTML('afterbegin',feedhtml);
}
if (trigger == 'account_create'){
var $newbie = tx.new_account_name,
$creator = tx.creator;
newbiehtml = '<div id="item" class="myJson">Новый пользователь <span>'+$newbie+'</span> ('+$creator+') </div>';
document.getElementById('nicedata').insertAdjacentHTML('afterbegin',newbiehtml);
}
if (trigger == 'account_update'){
// Обновление аккаунтов
}
if (trigger == 'account_witness_vote'){
var $acc = tx.account,
$wit = tx.witness;
votewhtml = '<div id="item" class="myJson">'+$acc+' голосует за делегата <span>'+$wit+'</span></div>';
document.getElementById('nicedata').insertAdjacentHTML('afterbegin',votewhtml);
}
}
};
connectGolos();
socket.onerror = function(event) {
document.getElementById('nicedata').insertAdjacentHTML('afterbegin', '<div class="alert">На сервере ноды произошла ошибка 502. Переподключение...</div>');
setTimeout(location.reload(), 1000); // На голосе часто ошибка 502 - в нашем случае перезагрузим страницу, если встретим такую ошибку.
connectGolos();
};
</script>
</body>
</html>