From d5108d040836cbbd31f40f754542d73cfbbac0b2 Mon Sep 17 00:00:00 2001 From: MEUNIER Thibaud Date: Thu, 11 Nov 2021 13:12:17 +0100 Subject: [PATCH] stable --- index.php | 48 ++++++++++----------------------------------- js/blockexplorer.js | 43 ++++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 60 deletions(-) diff --git a/index.php b/index.php index a56afa8..1814679 100644 --- a/index.php +++ b/index.php @@ -37,31 +37,18 @@ }); $(window).scroll(function() { - if (isInViewport(document.querySelector('footer'))) - { - //blockchainExplorer.addBottomBlock(); - console.log("Scroll to footer detected !"); - } + var element = document.getElementById('blockchain'); + var offset = element.getBoundingClientRect().top - element.offsetParent.getBoundingClientRect().top; + const top = window.pageYOffset + window.innerHeight - offset; - if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) { - // blockchainExplorer.addBottomBlock(); - console.log("Scroll to footer detected !"); - } - - $(".slideanim").each(function(){ - var pos = $(this).offset().top; - var winTop = $(window).scrollTop(); - if (pos < winTop + 600) { - blockchainExplorer.addBottomBlock(); - $(this).addClass("slide"); - } - }); - + if (top === element.scrollHeight) { + console.log("bottom"); + blockchainExplorer.addBottomBlock(); + } }); - blockchainExplorer.init(0); + showInfos(); - //toggleInfos(); }); var isInViewport = function (elem) { @@ -76,13 +63,7 @@ function showInfos() { - var flag = 2*parseInt($('#mode_selector').val()); - - $('#blockchain').html(''); - - if ($('#mode_checkbox').is(":checked")) flag += 1; - - blockchainExplorer.init(flag); + blockchainExplorer.init(parseInt($('#mode_selector').val())); } function toggleInfos() @@ -122,7 +103,7 @@

An image for each block of the BTC Blockchain
Click here to buy a block as an NFT -
@@ -134,14 +115,5 @@
-
- Click to see more blocks -
- - diff --git a/js/blockexplorer.js b/js/blockexplorer.js index f5bb78b..6423885 100644 --- a/js/blockexplorer.js +++ b/js/blockexplorer.js @@ -75,14 +75,13 @@ blockchainExplorer = function(){ _flag_nav = false; blockName = _getblockNameFromHash(block.hash); - // if (blockName != '') blockName = ' ( '+blockName+' )'; - if (_mode > 1) if (block.hash == _liste_blocks['TOP']) { div_label = 'LAST'; if (blockName == '') blockName = 'LAST'; } + if (blockName == '') blockName = block.height; opacity='1.0'; visibility='hidden'; @@ -90,23 +89,20 @@ blockchainExplorer = function(){ opacity='0.3'; visibility='visible'; } - contenu += '
'; contenu += '
'; contenu += ' '; - if (_mode == 3 ) contenu += ' '; - contenu += ' '; + contenu += ' '; contenu += ' '; contenu += ' '; contenu += ' '; contenu += ' '; contenu += ' '; - if (_mode != 3 ) contenu += ' '; + contenu += ' '; contenu += ' '; contenu += '
name'+blockName+'
height'+block.height+'
block'+blockName+'
timestamp'+_formatDate(block.time)+'
nonce'+block.nonce+'
nb tx'+block.n_tx+'
outputs'+_precisionRound(block.topisto_outputs).toFixed(4)+'
inputs'+_precisionRound(block.topisto_inputs).toFixed(4)+'
fees'+_precisionRound(block.topisto_fees).toFixed(4)+'
fees'+_precisionRound(block.topisto_fees).toFixed(4)+'
reward'+_precisionRound(block.topisto_reward).toFixed(4)+'
'; contenu += '
'; - contenu += '
'; $('#info_'+div_label).html(contenu); @@ -245,24 +241,24 @@ blockchainExplorer = function(){ // Récursivité pour précharger par paquets // Tant qu'on n'est pas sur le GENESIS - if (data.height > 0) + if (data.height > 0) switch(_mode) { case 0: - case 1: - // Récursivité pour précharger par paquets - _liste_blocks['BOTTOM'] = data.prev; + // En mode "Full Blockchain", on suit le chainage + _liste_blocks['BOTTOM'] = data.prev; break; - case 2: - case 3: - _liste_blocks['BOTTOM'] = _known_blocks[_liste_blocks['LENGTH']-1].hash; + case 1: + // En mode "Blocks Connus", on prend le prochain de la liste + _liste_blocks['BOTTOM'] = _known_blocks[_liste_blocks['LENGTH']-1].hash; break; } - } function _addBottomBlock() - { + { + console.log('add '+_liste_blocks['BOTTOM']); + // Mettre les infos du block block_hash = '?block_hash='+_liste_blocks['BOTTOM']; $.getJSON('data/getBlockInfo.php'+block_hash, function( data ) { @@ -276,14 +272,15 @@ blockchainExplorer = function(){ // Maintenir la Liste _maintenirListe(data); - if (_liste_blocks['LENGTH'] % 10) _addBottomBlock(); + if (data.height > 0) + if (_liste_blocks['LENGTH'] % 5) _addBottomBlock(); }); } function _initBlockchain(block_name) { - var block_hash = ''; + var block_hash_url = 'data/getBlockInfo.php'; _liste_blocks = []; _liste_blocks['LENGTH'] = 0; @@ -291,17 +288,19 @@ blockchainExplorer = function(){ $(document).scrollTop( $("#explorer").offset().top ); $('#blockchain').html(''); - if (block_name != 'LAST') block_hash = '?block_hash='+_getblocHashFromName(block_name); - $.getJSON('data/getBlockInfo.php'+block_hash, function( data ) { + + if (block_name != 'LAST') block_hash_url += '?block_hash='+_getblocHashFromName(block_name); + + $.getJSON(block_hash_url, function( data ) { div_label = data.height; _liste_blocks['TOP'] = data.hash; - _maintenirListe(data); - _addDivForBlock(div_label); _addInfoForBlock(data); + _maintenirListe(data); + // Cela fout le boxon pour l'instant // blockchainListener.addBlockHook(_addTopBlock);