Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Voice Explorer</title>
- <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;
- }
- #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>
- </header>
- <div id="sila"><b>Вычисление силы голоса...</b></div>
- <div id="nicedata"></div><div id="result"></div>
- <script>
- var stream = document.getElementById('result'), nicestream = document.getElementById('nicedata'), oneitem = document.getElementById('item'),
- socket = new WebSocket('wss://ws.golos.io'), account = 'vik';
- var movementTotal, silaTotal, lastblock, startblock;
- function connectGolos(){
- socket.onopen = function(event) {
- setInterval(function() {
- socket.send(JSON.stringify({ // Делаем запрос на возвращение глобальных динамических данных
- id: 1,
- method: 'get_dynamic_global_properties',
- 'params': []
- }));
- lastblock++; // Увеличиваем номер блока на 1 каждый раз, когда происходит socket.onmessage
- }, 3000);
- // Делаем такой запрос каждые 3000 милисикунд - частота генерации блока
- };
- } connectGolos();
- socket.onerror = function (event) {
- stream.insertAdjacentHTML('afterbegin','<div class="alert">На сервере ноды произошла ошибка 502. Переподключение...</div>');
- setTimeout(location.reload(), 1000); // На голосе часто ошибка 502 - в нашем случае перезагрузим страницу, если встретим такую ошибку.
- };
- 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'); }, 500);
- }
- 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: [
- [account] // Переменная с ранее указаным ником
- ]
- }));
- 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" ) { // если блок не пустой
- var fulldata = JSON.stringify(data.result);
- stream.insertAdjacentHTML('afterbegin','<div id="item" class="myJson fulldata">'+fulldata+'</div>');
- itemShow(); // анимация
- tx = data.result.transactions[0].operations[0][1]; // Транзакция > Операция > пропускаем первое значение... > Массив (не json)
- txJson = JSON.stringify(tx); // Переводим в json и получаем: Транзакция > Операция > Массив в json формате
- trigger = data.result.transactions[0].operations[0][0];// JSON.stringify(data.result.transactions[0].operations[0][0]); // Первое значение операции - поможет в идентификации события
- type = trigger;
- $witness = data.result.witness;
- $timestamp = data.result.timestamp;
- $voter = tx.voter;
- $power = tx.weight;
- $author = tx.author;
- $permlink = tx.permlink;
- $parent = tx.parent_author;
- $body = tx.body;
- $title = tx.title;
- $newbie = tx.new_account_name;
- $mentionfrom = JSON.stringify(tx.from);
- $mention = JSON.stringify(tx.to);
- $mentmemo = JSON.stringify(tx.memo);
- $amount = JSON.stringify(tx.amount);
- //$memocut = mentmemo.slice(26); - обрезаем первые 26 символов в упоминании
- document.getElementById('merkle').innerHTML = ('id <span>'+merkle+'</span> Время блока '+$timestamp);
- document.getElementById('witness').innerHTML = ('Владелец текущей ноды <a href="https://golos.io/@'+$witness+'">@'+$witness+'</a>');
- if (typeof $voter !== 'undefined' && typeof $author !== 'undefined'){
- nicestream.insertAdjacentHTML('afterbegin','<p id="item" class="myJson '+type+'"> <a href="https://golos.io/@'+$voter+'/">'+$voter+'</a> голосует за <a href="https://golos.io/@'+$author+'/">'+$author+'</a> сила '+$power+'.</p>');
- itemShow();
- }
- if (trigger = 'comment' && typeof $author!== 'undefined'&& typeof $title!== 'undefined'){
- nicestream.insertAdjacentHTML('afterbegin','<p id="item" class="myJson '+type+'"><a href="https://golos.io/@'+$author+'/">'+$author+'</a> пишет <a href="https://golos.io/@'+$parent+'/"> '+$parent+' </a> </p> <div class="textpost scrl"><h4>'+$title+'</h4> '+$body+'</div>');
- itemShow();
- }
- if (trigger = 'custom_json'){
- $df = JSON.stringify(txJson.json);
- $dfollower = $df[1].follower;
- $dfollowin = $df[1].following;
- nicestream.insertAdjacentHTML('afterbegin','<p id="item" class="myJson '+type+'"> <span>'+$dfollower+'</span> подписывается на <span>'+$dfollowin+'</span></p>');
- itemShow();
- }
- /* Условия ниже оставим на потом.
- if (trigger = 'transfer'){
- //nicestream.insertAdjacentHTML('afterbegin','<p id="item" class="myJson '+trigger+'"> Трансфер '+$amount+' от <span>'+$mentionfrom+'</span> к <span>'+$mention+'</span> примечание: <em>'+$mentmemo+'</em></p>');
- }
- if (trigger = 'feed_publish'){
- }
- if (trigger = 'pow2'){
- }
- if (trigger = 'account_create'){
- }
- if (trigger = 'account_update'){
- } */
- }
- };
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement