2019-02-02 03:49:11 +00:00
|
|
|
requested = []
|
|
|
|
|
|
|
|
var windowHeight = window.innerHeight;
|
2019-04-16 05:02:09 +00:00
|
|
|
webpassword = webpass
|
2019-04-16 17:04:51 +00:00
|
|
|
newPostForm = document.getElementById('addMsg')
|
|
|
|
|
|
|
|
function appendMessages(msg){
|
|
|
|
var humanDate = new Date(0)
|
2019-04-20 22:55:54 +00:00
|
|
|
if (msg.length == 0){
|
|
|
|
return
|
|
|
|
}
|
2019-04-16 17:04:51 +00:00
|
|
|
var msg = JSON.parse(msg)
|
|
|
|
var dateEl = document.createElement('span')
|
|
|
|
var el = document.createElement('div')
|
|
|
|
var msgDate = msg['meta']['time']
|
|
|
|
if (msgDate === undefined){
|
|
|
|
msgDate = 'unknown'
|
2019-02-02 03:49:11 +00:00
|
|
|
}
|
|
|
|
else{
|
2019-04-16 17:04:51 +00:00
|
|
|
humanDate.setUTCSeconds(msgDate)
|
|
|
|
msgDate = humanDate.toDateString() + ' ' + humanDate.toTimeString()
|
2019-02-02 03:49:11 +00:00
|
|
|
}
|
2019-04-16 17:04:51 +00:00
|
|
|
dateEl.textContent = msgDate
|
2019-02-02 03:49:11 +00:00
|
|
|
el.className = 'entry'
|
2019-04-16 17:04:51 +00:00
|
|
|
el.innerText = msg['content']
|
|
|
|
document.getElementById('feed').appendChild(dateEl)
|
2019-02-02 03:49:11 +00:00
|
|
|
document.getElementById('feed').appendChild(el)
|
|
|
|
document.getElementById('feed').appendChild(document.createElement('br'))
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBlocks(){
|
|
|
|
if (document.getElementById('none') !== null){
|
|
|
|
document.getElementById('none').remove();
|
|
|
|
|
|
|
|
}
|
|
|
|
var feedText = httpGet('/getblocksbytype/txt')
|
|
|
|
var blockList = feedText.split(',')
|
|
|
|
for (i = 0; i < blockList.length; i++){
|
|
|
|
if (! requested.includes(blockList[i])){
|
2019-04-16 05:02:09 +00:00
|
|
|
bl = httpGet('/getblockdata/' + blockList[i])
|
2019-02-02 03:49:11 +00:00
|
|
|
appendMessages(bl)
|
|
|
|
requested.push(blockList[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('refreshFeed').onclick = function(){
|
|
|
|
getBlocks()
|
2019-04-16 17:04:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newPostForm.onsubmit = function(){
|
2019-04-20 22:55:54 +00:00
|
|
|
var message = document.getElementById('newMsgText').value
|
|
|
|
var postData = {'message': message, 'type': 'txt', 'encrypt': false}
|
|
|
|
postData = JSON.stringify(postData)
|
|
|
|
newPostForm.style.display = 'none'
|
|
|
|
fetch('/insertblock', {
|
|
|
|
method: 'POST',
|
|
|
|
body: postData,
|
|
|
|
headers: {
|
|
|
|
"content-type": "application/json",
|
|
|
|
"token": webpass
|
|
|
|
}})
|
|
|
|
.then((resp) => resp.text()) // Transform the data into json
|
|
|
|
.then(function(data) {
|
|
|
|
newPostForm.style.display = 'block'
|
|
|
|
alert('Queued for submission!')
|
|
|
|
})
|
2019-04-16 17:04:51 +00:00
|
|
|
return false
|
2019-02-02 03:49:11 +00:00
|
|
|
}
|