// placeholder of API peers response var coin_types = ['BTC', 'BTCD']; var response = { "peers": [ { "ipaddr": "127.0.0.1", "protover": 60013, "relay": 1, "height": 854849, "rank": 0, "usock": 4, "ready": 1449777119, "msgcounts": { "version": 1, "verack": 1, "getaddr": 0, "addr": 2, "inv": 0, "getdata": 0, "notfound": 0, "getblocks": 0, "getheaders": 0, "headers": 0, "tx": 0, "block": 0, "mempool": 0, "ping": 0, "pong": 0, "reject": 0, "filterload": 0, "filteradd": 0, "filterclear": 0, "merkleblock": 0, "alert": 0 } }, { "ipaddr": "234.0.0.1", "protover": 50013, "relay": 1, "height": 584849, "rank": 1, "usock": 4, "ready": 1449777119, "msgcounts": { "version": 1, "verack": 1, "getaddr": 0, "addr": 2, "inv": 0, "getdata": 0, "notfound": 0, "getblocks": 0, "getheaders": 0, "headers": 0, "tx": 0, "block": 0, "mempool": 0, "ping": 0, "pong": 0, "reject": 0, "filterload": 0, "filteradd": 0, "filterclear": 0, "merkleblock": 0, "alert": 0 } }, { "ipaddr": "345.0.0.1", "protover": 62013, "relay": 1, "height": 354849, "rank": 1, "usock": 4, "ready": 1449777119, "msgcounts": { "version": 1, "verack": 1, "getaddr": 0, "addr": 2, "inv": 0, "getdata": 0, "notfound": 0, "getblocks": 0, "getheaders": 0, "headers": 0, "tx": 0, "block": 0, "mempool": 0, "ping": 0, "pong": 0, "reject": 0, "filterload": 0, "filteradd": 0, "filterclear": 0, "merkleblock": 0, "alert": 0 } }, { "ipaddr": "567.0.0.1", "protover": 30013, "relay": 1, "height": 454849, "rank": 0, "usock": 4, "ready": 1449777119, "msgcounts": { "version": 1, "verack": 1, "getaddr": 0, "addr": 2, "inv": 0, "getdata": 0, "notfound": 0, "getblocks": 0, "getheaders": 0, "headers": 0, "tx": 0, "block": 0, "mempool": 0, "ping": 0, "pong": 0, "reject": 0, "filterload": 0, "filteradd": 0, "filterclear": 0, "merkleblock": 0, "alert": 0 } }, { "ipaddr": "321.0.0.1", "protover": 55013, "relay": 1, "height": 444849, "rank": 2, "usock": 4, "ready": 1449777119, "msgcounts": { "version": 1, "verack": 1, "getaddr": 0, "addr": 2, "inv": 0, "getdata": 0, "notfound": 0, "getblocks": 0, "getheaders": 0, "headers": 0, "tx": 0, "block": 0, "mempool": 0, "ping": 0, "pong": 0, "reject": 0, "filterload": 0, "filteradd": 0, "filterclear": 0, "merkleblock": 0, "alert": 0 } }, { "ipaddr": "764.0.0.1", "protover": 60013, "relay": 1, "height": 134849, "rank": 2, "usock": 4, "ready": 3249777119, "msgcounts": { "version": 1, "verack": 1, "getaddr": 0, "addr": 2, "inv": 0, "getdata": 0, "notfound": 0, "getblocks": 0, "getheaders": 0, "headers": 0, "tx": 0, "block": 0, "mempool": 0, "ping": 0, "pong": 0, "reject": 0, "filterload": 0, "filteradd": 0, "filterclear": 0, "merkleblock": 0, "alert": 0 } }, { "ipaddr": "327.0.0.1", "protover": 60013, "relay": 1, "height": 854849, "rank": 3, "usock": 4, "ready": 1449777119, "msgcounts": { "version": 1, "verack": 1, "getaddr": 0, "addr": 2, "inv": 0, "getdata": 0, "notfound": 0, "getblocks": 0, "getheaders": 0, "headers": 0, "tx": 0, "block": 0, "mempool": 0, "ping": 0, "pong": 0, "reject": 0, "filterload": 0, "filteradd": 0, "filterclear": 0, "merkleblock": 0, "alert": 0 } }, { "ipaddr": "765.0.0.1", "protover": 60013, "relay": 1, "height": 854849, "rank": 0, "usock": 4, "ready": 1449777119, "msgcounts": { "version": 1, "verack": 1, "getaddr": 0, "addr": 2, "inv": 0, "getdata": 0, "notfound": 0, "getblocks": 0, "getheaders": 0, "headers": 0, "tx": 0, "block": 0, "mempool": 0, "ping": 0, "pong": 0, "reject": 0, "filterload": 0, "filteradd": 0, "filterclear": 0, "merkleblock": 0, "alert": 0 } }, { "ipaddr": "255.0.0.1", "protover": 60013, "relay": 1, "height": 854849, "rank": 2, "usock": 4, "ready": 1449777119, "msgcounts": { "version": 1, "verack": 1, "getaddr": 0, "addr": 2, "inv": 0, "getdata": 0, "notfound": 0, "getblocks": 0, "getheaders": 0, "headers": 0, "tx": 0, "block": 0, "mempool": 0, "ping": 0, "pong": 0, "reject": 0, "filterload": 0, "filteradd": 0, "filterclear": 0, "merkleblock": 0, "alert": 0 } } ], "maxpeers": 32, "coin": "BTCD", "tag": "12697016274367621769" }; var favPeers = []; var getHtmlRow = function (id, peer) { var row = ''; row = ''; row += '' + peer.ipaddr + ''; row += '' + peer.cointype + ''; row += '' + peer.height + ''; row += '' + peer.rank + ''; if ($.inArray(id, favPeers) == -1) { row += ''; // row += 'bookmark_border'; } else { row += ''; // row += 'bookmark' } row += ''; return row; }; var addPeerToFav = function (id) { if ($.inArray(id, favPeers) == -1) { favPeers.push(parseInt(id)); console.log('@ peer faved', favPeers); } // refresh grid renderPeersGrid(false); }; var removePeerFromFav = function (id) { for (var index = 0; index < favPeers.length; index++) { if (id == favPeers[index]) { favPeers.splice(index, 1); console.log('@ peer unfaved', favPeers); break; } } // refresh grid renderPeersGrid(document.getElementById('cbShowFavoritePeers').checked); }; var renderPeersGrid = function (favoritesOnly = false) { console.log('@ peer print grid') var peersTableAllHtml = ''; for (var i = 0; i < response.peers.length; i++) { if (favoritesOnly == true && $.inArray(i, favPeers) == -1) { continue; } response.peers[i].cointype = response.coin peersTableAllHtml += getHtmlRow(i, response.peers[i]); } document.getElementById('peersTableBody').innerHTML = peersTableAllHtml; }; document.getElementById('cbShowFavoritePeers').onclick = function () { // if (document.getElementById('cbShowFavoritePeers').checked == true) { // // document.getElementById('peersTableBody').style.display = 'none'; // // document.getElementById('peersTable_fav').style.display = 'block'; // $('#peersTableBody').hide(); // $('#peersTable_fav').show(); // } // else { // // document.getElementById('peersTableBody').style.display = 'block'; // // document.getElementById('peersTable_fav').style.display = 'none'; // $('#peersTableBody').show(); // $('#peersTable_fav').hide(); // } renderPeersGrid(document.getElementById('cbShowFavoritePeers').checked); }; var startPeerManagement = function () { renderPeersGrid(); };