Onionr/onionr/static-data/www/board/board.js

69 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2019-02-02 03:49:11 +00:00
requested = []
var windowHeight = window.innerHeight;
2019-04-16 05:02:09 +00:00
webpassword = webpass
newPostForm = document.getElementById('addMsg')
function appendMessages(msg){
var humanDate = new Date(0)
if (msg.length == 0){
return
}
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{
humanDate.setUTCSeconds(msgDate)
msgDate = humanDate.toDateString() + ' ' + humanDate.toTimeString()
2019-02-02 03:49:11 +00:00
}
dateEl.textContent = msgDate
2019-02-02 03:49:11 +00:00
el.className = 'entry'
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()
}
newPostForm.onsubmit = function(){
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!')
})
return false
2019-02-02 03:49:11 +00:00
}