2020-06-25 22:30:34 +00:00
|
|
|
/*
|
|
|
|
Onionr - Private P2P Communication
|
|
|
|
|
|
|
|
Get and show recent blocks
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
|
|
*/
|
2020-06-21 07:27:55 +00:00
|
|
|
var getRecent = function(){
|
|
|
|
var recentSource = new EventSourcePolyfill('/recentblocks', {
|
|
|
|
headers: {
|
|
|
|
"token": webpass
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
recentSource.onmessage = function(e){
|
|
|
|
if (e.data == "none"){
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var existing = document.getElementsByClassName('recentBlockList')[0].innerText;
|
|
|
|
let data = JSON.parse(e.data)
|
|
|
|
Object.entries(data.blocks).forEach(([key, value]) => {
|
|
|
|
if (existing.includes(key)){
|
|
|
|
return
|
|
|
|
}
|
2020-08-23 11:29:40 +00:00
|
|
|
existing = "\n" + key + " - " + value + "\n" + existing
|
2020-06-21 07:27:55 +00:00
|
|
|
})
|
|
|
|
document.getElementsByClassName('recentBlockList')[0].innerText = existing
|
|
|
|
console.debug(data)
|
|
|
|
}
|
|
|
|
return recentSource
|
|
|
|
}
|
|
|
|
recentSource = getRecent()
|
|
|
|
function toggleRecentStream() {
|
|
|
|
if (document.hidden){
|
|
|
|
console.debug("Stopped recent block stream")
|
|
|
|
recentSource.close()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (document.getElementsByClassName('recentModal')[0].classList.contains('is-active')){
|
|
|
|
recentSource.close()
|
|
|
|
getRecent()
|
2020-06-20 10:31:51 +00:00
|
|
|
}
|
2020-06-21 07:27:55 +00:00
|
|
|
}
|
2020-06-20 10:31:51 +00:00
|
|
|
|
|
|
|
|
2020-06-21 07:27:55 +00:00
|
|
|
document.getElementsByClassName('recentBlocksBtn')[0].onclick = function(){
|
|
|
|
document.getElementsByClassName('recentModal')[0].classList.add('is-active')
|
2020-06-20 10:31:51 +00:00
|
|
|
}
|
2020-06-21 07:27:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
document.getElementsByClassName('recentBlocksBtn')
|
|
|
|
document.addEventListener("visibilitychange", toggleRecentStream, false);
|
|
|
|
|
|
|
|
document.getElementsByClassName('closeRecentModal')[0].onclick = function(){
|
|
|
|
document.getElementsByClassName('recentBlockList')[0].innerText = ""
|
|
|
|
document.getElementsByClassName('recentModal')[0].classList.remove('is-active')
|
|
|
|
}
|