posts are now sorted and
This commit is contained in:
parent
c362ff33c0
commit
0219c3bc77
39
hush-hush.js
39
hush-hush.js
@ -17,8 +17,8 @@
|
||||
*/
|
||||
var findMessageIntervalTime = 5000
|
||||
var publicNodes = [
|
||||
"67xpi7z753tbmylc7etrifjxqeyizoiqg6n7p5we6e4nblit5bqenqad",
|
||||
"mpidhsfpmdgxxc5ygqluwtxptgne5swp5nkjzdre6tmnent7zqwp3cyd"
|
||||
"4wbarqtxh6zasoxxftakrellcjzztcib7bqth4u3igof5fskrrvrk4yd",
|
||||
"zl67stwxpjkntaxcfdhj3dvayculoojju6eek2jhsrdz6uwf224o6oqd"
|
||||
]
|
||||
var messageHashes = []
|
||||
var blocks = []
|
||||
@ -52,8 +52,14 @@ setInterval(function(){shuffleArray(publicNodes)}, 5000)
|
||||
|
||||
|
||||
// Make Tor connect to each node to reduce future connection time
|
||||
publicNodes.forEach(element => {
|
||||
fetch("http://" + element + ".onion/ping")
|
||||
publicNodes.forEach(node => {
|
||||
let doPing = async function(){
|
||||
let res = await(await fetch("http://" + node + ".onion/ping")).text()
|
||||
if (res !== "pong!"){
|
||||
console.debug(node)
|
||||
}
|
||||
}
|
||||
doPing()
|
||||
})
|
||||
|
||||
function getCurrentNode(){
|
||||
@ -65,22 +71,39 @@ function getCurrentNode(){
|
||||
}
|
||||
|
||||
function addMessage(message, timestamp){
|
||||
function sortEntries() {
|
||||
var entries = document.getElementsByClassName('entry')
|
||||
|
||||
if (entries.length > 1) {
|
||||
const sortBy = 'data-epoch'
|
||||
const parent = entries[0].parentNode
|
||||
|
||||
const sorted = Array.from(entries).sort((a, b) => b.getAttribute(sortBy) - a.getAttribute(sortBy))
|
||||
sorted.forEach(element => parent.appendChild(element))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
message = DOMPurify.sanitize(marked(message),
|
||||
{FORBID_ATTR: ['style'],
|
||||
ALLOWED_TAGS: ['b', 'p', 'em', 'i', 'a',
|
||||
ALLOWED_TAGS: ['b', 'p', 'em', 'i', 'a', 'strong', 'sub', 'small', 'ul', 'li', 'ol', 'strike',
|
||||
'tr', 'td', 'th', 'table', 'thead', 'tfoot', 'colgroup', 'col', 'caption', 'marquee',
|
||||
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'pre', 'center', 'br', 'hr']})
|
||||
|
||||
let childEl = document.createElement('div')
|
||||
childEl.classList.add('content')
|
||||
childEl.innerHTML = message
|
||||
var tmpl = document.getElementById("cMsgTemplate")
|
||||
timestamp = timestamp.toString()
|
||||
|
||||
let newEl = tmpl.content.cloneNode(true)
|
||||
newEl.children[0].setAttribute('data-epoch', timestamp)
|
||||
newEl.children[0].classList.add("entry")
|
||||
newEl.children[0].children[0].children[0].innerText = ""
|
||||
newEl.children[0].children[0].children[0].append(childEl)
|
||||
newEl.children[0].children[0].children[2].innerText = timestamp
|
||||
newEl.children[0].children[0].children[2].innerText = new Date(timestamp * 1000).toString().split('GMT')[0]
|
||||
document.getElementsByClassName("messageFeed")[0].prepend(newEl)
|
||||
sortEntries()
|
||||
}
|
||||
|
||||
async function apiGET(path, queryString, raw=false){
|
||||
@ -102,7 +125,7 @@ async function findMessages(){
|
||||
setTimeout(function(){findMessages()}, 1000)
|
||||
return
|
||||
}
|
||||
let messages = (await apiGET("getblocklist", "?type=brd")).split('\n')
|
||||
let messages = (await apiGET("getblocklist", "?type=kic")).split('\n')
|
||||
messages.forEach(block => {
|
||||
if (!block) { return}
|
||||
block = reconstructHash(block)
|
||||
@ -127,7 +150,7 @@ async function findMessages(){
|
||||
return
|
||||
}
|
||||
blocks.push(block)
|
||||
addMessage(data, new Date(metadata['time'] * 1000))
|
||||
addMessage(data, metadata['time'])
|
||||
updateMemoryUsage(data, block)
|
||||
})
|
||||
})
|
||||
|
30
index.html
30
index.html
@ -39,27 +39,29 @@
|
||||
<p>kiccan is a message board program that utilizes the <a href="https://onionr.net/">Onionr</a> network.</p>
|
||||
<p>posts are rate-limited using a partial hash collision proof of work function.</p>
|
||||
<p>⚠️ the host of this web page has no control over posts. Browse and post at your own risk.</p>
|
||||
<p class="is-pulled-right">post memory usage: <span id="memUsage">0kb</span></p>
|
||||
<p class="is-hidden has-text-warning noTor">You do not seem to be able to reach .onion services. Please use Tor Browser or Brave Browser's private tabs.</p>
|
||||
<p class="is-pulled-right">feed size: <span id="memUsage">0kb</span> | page size: 289kb</p>
|
||||
<p class="is-hidden has-text-warning noTor">You do not seem to be able to reach .onion services. Please use Tor Browser.</p>
|
||||
</div>
|
||||
</section>
|
||||
<div class="container messageCreator">
|
||||
<div class="columns">
|
||||
<div class="column is-two-fifths">
|
||||
<div class="postForm">
|
||||
<div class="control">
|
||||
<p>Markdown is supported, except for images, styles and scripts.</p>
|
||||
<textarea class="textarea" placeholder="Draft a post..." id="postMessageField"></textarea>
|
||||
<section class="section">
|
||||
<div class="container messageCreator">
|
||||
<div class="columns">
|
||||
<div class="column is-two-fifths">
|
||||
<div class="postForm">
|
||||
<div class="control">
|
||||
<p>Markdown and limited HTML is supported.</p>
|
||||
<textarea class="textarea" placeholder="Draft a post..." id="postMessageField"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="control">
|
||||
<a class="button is-primary" id="createMessageBtn">Create Post</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control">
|
||||
<a class="button is-primary" id="createMessageBtn">Create Post</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<div class="container messageFeed">
|
||||
</div>
|
||||
<template id="cMsgTemplate">
|
||||
|
@ -1,16 +1,38 @@
|
||||
/*
|
||||
hush-hush: anonymous message board using the onionr network
|
||||
Copyright (C) 2020 Kevin Froman
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
document.getElementById("createMessageBtn").onclick = async function(){
|
||||
document.getElementById("createMessageBtn").setAttribute("disabled", true)
|
||||
|
||||
let field = document.getElementById("postMessageField")
|
||||
|
||||
let payload = {
|
||||
"metadata": {
|
||||
'time': Math.floor((Date.now() / 1000)),
|
||||
'meta': JSON.stringify({'type': 'brd', 'ch': 'global'})
|
||||
'meta': JSON.stringify({'type': 'kic', 'ch': 'global'})
|
||||
},
|
||||
"data": field.value,
|
||||
"difficulty": difficulty.length / 2
|
||||
}
|
||||
powWorker.postMessage(JSON.stringify(payload))
|
||||
|
||||
setTimeout(function(){
|
||||
document.getElementById("createMessageBtn").removeAttribute("disabled")
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
powWorker.addEventListener('message', function(e) {
|
||||
|
@ -1,3 +1,20 @@
|
||||
/*
|
||||
hush-hush: anonymous message board using the onionr network
|
||||
Copyright (C) 2020 Kevin Froman
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
function reconstructHash(hash){
|
||||
return hash.padStart(64, 0)
|
||||
}
|
||||
|
17
powworker.js
17
powworker.js
@ -1,3 +1,20 @@
|
||||
/*
|
||||
hush-hush: anonymous message board using the onionr network
|
||||
Copyright (C) 2020 Kevin Froman
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
importScripts("onionr-jspow/index.js")
|
||||
importScripts("sha3.js")
|
||||
|
||||
|
@ -1,7 +1,27 @@
|
||||
/*
|
||||
hush-hush: anonymous message board using the onionr network
|
||||
Copyright (C) 2020 Kevin Froman
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
var lookupWorker = new Worker('peer-lookup.js');
|
||||
var powWorker = new Worker("powworker.js")
|
||||
|
||||
lookupWorker.addEventListener('message', function(e) {
|
||||
if (publicNodes.includes(e.data)){
|
||||
return
|
||||
}
|
||||
publicNodes.push(e.data)
|
||||
}, false);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user