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')
|
2019-07-17 05:10:39 +00:00
|
|
|
firstLoad = true
|
2019-04-16 17:04:51 +00:00
|
|
|
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)
|
2019-06-28 21:24:34 +00:00
|
|
|
var dateEl = document.createElement('div')
|
2019-04-16 17:04:51 +00:00
|
|
|
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)
|
2019-07-17 05:10:39 +00:00
|
|
|
msgDate = humanDate.toDateString()
|
2019-02-02 03:49:11 +00:00
|
|
|
}
|
|
|
|
el.className = 'entry'
|
2019-04-16 17:04:51 +00:00
|
|
|
el.innerText = msg['content']
|
2019-06-28 21:24:34 +00:00
|
|
|
|
|
|
|
/* Template Test */
|
|
|
|
// Test to see if the browser supports the HTML template element by checking
|
|
|
|
// for the presence of the template element's content attribute.
|
|
|
|
if ('content' in document.createElement('template')) {
|
|
|
|
|
|
|
|
// Instantiate the table with the existing HTML tbody
|
|
|
|
// and the row with the template
|
2019-07-17 05:10:39 +00:00
|
|
|
var template = document.getElementById('cMsgTemplate')
|
2019-06-28 21:24:34 +00:00
|
|
|
|
|
|
|
// Clone the new row and insert it into the table
|
2019-07-17 05:10:39 +00:00
|
|
|
var feed = document.getElementById("feed")
|
2019-06-28 21:24:34 +00:00
|
|
|
var clone = document.importNode(template.content, true);
|
2019-07-17 05:10:39 +00:00
|
|
|
var div = clone.querySelectorAll("div")
|
|
|
|
div[2].textContent = msg['content']
|
|
|
|
div[3].textContent = msgDate
|
2019-06-28 21:24:34 +00:00
|
|
|
|
2019-07-17 05:10:39 +00:00
|
|
|
if (firstLoad){
|
|
|
|
feed.appendChild(clone)
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
feed.prepend(clone)
|
|
|
|
}
|
2019-06-28 21:24:34 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// Find another way to add the rows to the table because
|
|
|
|
// the HTML template element is not supported.
|
|
|
|
}
|
2019-02-02 03:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getBlocks(){
|
|
|
|
if (document.getElementById('none') !== null){
|
|
|
|
document.getElementById('none').remove();
|
|
|
|
|
|
|
|
}
|
|
|
|
var feedText = httpGet('/getblocksbytype/txt')
|
2019-07-17 05:10:39 +00:00
|
|
|
var blockList = feedText.split(',').reverse()
|
2019-02-02 03:49:11 +00:00
|
|
|
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])
|
|
|
|
}
|
|
|
|
}
|
2019-07-17 05:10:39 +00:00
|
|
|
firstLoad = false
|
2019-02-02 03:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|