markdown support added

This commit is contained in:
Kevin Froman 2020-10-05 08:42:20 +00:00
parent c185b0b02a
commit 1889989e20
6 changed files with 40 additions and 15 deletions

View File

@ -17,7 +17,8 @@
*/
var findMessageIntervalTime = 5000
var publicNodes = [
"yre3tmbu25lcogl42xlh73wfchgbx3unz2zz3ttyiylj6gaq5mzhevid"
"yre3tmbu25lcogl42xlh73wfchgbx3unz2zz3ttyiylj6gaq5mzhevid",
"ltqmmfww3tue6tibtyfc4kk7edh3owewxwcgrkvwqw4cwgd3w3zcj6id"
]
var messageHashes = []
var blocks = []
@ -33,6 +34,8 @@ function shuffleArray(array) {
[array[i], array[j]] = [array[j], array[i]];
}
}
shuffleArray(publicNodes)
//https://stackoverflow.com/q/10420352
function getReadableFileSizeString(fileSizeInBytes) {
var i = -1;
@ -62,12 +65,22 @@ function getCurrentNode(){
}
function addMessage(message, timestamp){
message = DOMPurify.sanitize(marked(message),
{FORBID_ATTR: ['style'],
ALLOWED_TAGS: ['b', 'p', 'em', 'i', 'a',
'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")
let newEl = tmpl.content.cloneNode(true)
newEl.children[0].children[0].children[0].innerText = message
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
document.getElementsByClassName("messageFeed")[0].append(newEl)
document.getElementsByClassName("messageFeed")[0].prepend(newEl)
}
async function apiGET(path, queryString, raw=false){
@ -91,6 +104,7 @@ async function findMessages(){
}
let messages = (await apiGET("getblocklist", "?type=brd")).split('\n')
messages.forEach(block => {
if (!block) { return}
block = reconstructHash(block)
if (!block.startsWith(difficulty)){console.debug("not difficulty reached:" + block); return}
@ -101,20 +115,20 @@ async function findMessages(){
// Size is size of data (not metadata) and block hash
document.getElementById('memUsage').innerText = getReadableFileSizeString(current + ((basicTextEncoder.encode(data)).length + block.length))
}
let metadata = JSON.parse(d.split("\n")[0])
console.debug(metadata)
//let data = d.split('\n')[1]
let data = d.substring(d.indexOf('\n') + 1);
try{
verifyBlock(d, block)
verifyTime()
verifyTime(metadata['time'])
}
catch(e){
console.debug(block + ":" + e)
return
}
let metadata = JSON.parse(d.split("\n")[0])
console.debug(metadata)
let data = d.split('\n')[1]
blocks.push(block)
addMessage(data, new Date(metadata['time']))
addMessage(data, new Date(metadata['time'] * 1000))
updateMemoryUsage(data, block)
})
})

View File

@ -14,6 +14,7 @@
<link rel="stylesheet" href="style.css">
<script src="tordetect.js" async></script>
<script src="marked.min.js" defer></script>
<script src="purify.min.js" defer></script>
<script src="sha3.js" defer></script>
<script src="onionr-jspow/index.js" defer></script>
<script src="onionr-blocks.js" defer></script>
@ -35,7 +36,7 @@
JavaScript is required for this app. The server has no knowledge of posts, so content must be served by P2P nodes.
</p></noscript>
<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>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>
@ -46,7 +47,8 @@
<div class="column is-two-fifths">
<div class="postForm">
<div class="control">
<textarea class="textarea" placeholder="Normal textarea"></textarea>
<p>Markdown is supported, except for images, styles and scripts.</p>
<textarea class="textarea" placeholder="Draft a post..."></textarea>
</div>
</div>
</div>

View File

@ -11,4 +11,9 @@ function verifyBlock(raw, hash){
}
}
function verifyTime(time){
let epoch = Math.round(Date.now() / 1000);
if ((epoch - time) > maxBlockAge){
throw new Error("Block is too old")
}
}

View File

@ -21,7 +21,8 @@ self.addEventListener('message', async function(e) {
let lookupPeer = async function(peer){
let newList = await (await fetch('http://' + peer + '.onion/pex')).text()
newList = newList.replace('.onion', '')
newList = newList.replaceAll('.onion', '')
return newList.split(',')
}
var data = JSON.parse(e.data)

3
purify.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -4,4 +4,4 @@
.messageCreator{
margin-bottom: 1em;
}
}