moved static data one directory up

This commit is contained in:
Kevin Froman 2019-09-23 17:56:05 -05:00
parent e4df34ef29
commit 09f6735961
124 changed files with 27 additions and 54 deletions

View file

@ -0,0 +1,19 @@
var checkbox = document.getElementById('refreshCheckbox')
function autoRefresh(){
if (! checkbox.checked){return}
getBlocks()
}
function setupInterval(){
if (checkbox.checked){
refreshInterval = setInterval(autoRefresh, 3000)
autoRefresh()
return
}
clearInterval(refreshInterval)
}
var refreshInterval = setInterval(autoRefresh, 3000)
setupInterval()
checkbox.onchange = function(){setupInterval}

219
static-data/www/board/board.js Executable file
View file

@ -0,0 +1,219 @@
/*
Onionr - Private P2P Communication
This file handles the boards/circles interface
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
requested = []
var windowHeight = window.innerHeight;
webpassword = webpass
newPostForm = document.getElementById('addMsg')
firstLoad = true
lastLoadedBoard = 'global'
loadingMessage = document.getElementById('loadingBoard')
let toggleLoadingMessage = function(){
switch (loadingMessage.style.display){
case "block":
case "inline":
case "inline-block":
loadingMessage.style.display = "none"
break;
default:
loadingMessage.style.display = "initial"
break;
}
}
fetch('/flow/version', {
method: 'GET',
headers: {
"token": webpass
}})
.then((resp) => resp.text()) // Transform the data into json
.then(function(data) {
document.getElementById('circlesVersion').innerText = data
})
function appendMessages(msg, blockHash, beforeHash){
var humanDate = new Date(0)
if (msg.length == 0){
return
}
//var msg = JSON.parse(msg)
var el = document.createElement('div')
var msgDate = msg['meta']['time']
var feed = document.getElementById("feed")
var beforeEl = null
if (msgDate === undefined){
msgDate = 'unknown'
}
else{
humanDate.setUTCSeconds(msgDate)
msgDate = humanDate.toLocaleTimeString() + ' ' + humanDate.toLocaleDateString()
}
el.className = 'entry'
el.innerText = msg['content']
if (beforeHash !== null){
for (x = 0; x < feed.children.length; x++){
if (feed.children[x].getAttribute('data-bl') === beforeHash){
beforeEl = feed.children[x]
}
}
}
/* 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
var template = document.getElementById('cMsgTemplate')
// Clone the new row and insert it into the table
var clone = document.importNode(template.content, true)
var div = clone.querySelectorAll("div")
var identicon = clone.querySelectorAll("img")
div[0].setAttribute('data-bl', blockHash)
div[2].textContent = msg['content']
if (typeof msg['meta']['signer'] != 'undefined' && msg['meta']['signer'].length > 0){
div[3].textContent = msg['meta']['signer'].substr(0, 5)
setHumanReadableIDOnPost(div[3], msg['meta']['signer'])
div[3].title = msg['meta']['signer']
identicon[0].src = "data:image/svg+xml;base64," + userIcon(msg['meta']['signer'])
}
else{
identicon[0].remove()
}
div[4].textContent = msgDate
loadingMessage.style.display = "none"
if (firstLoad){
//feed.appendChild(clone)
feed.prepend(clone)
firstLoad = false
}
else{
if (beforeEl === null){
feed.prepend(clone)
}
else{
beforeEl.insertAdjacentElement("beforebegin", clone.children[0])
}
}
}
}
function getBlocks(){
var feed = document.getElementById("feed")
var ch = document.getElementById('feedIDInput').value
if (lastLoadedBoard !== ch){
toggleLoadingMessage()
while (feed.firstChild) {
feed.removeChild(feed.firstChild);
}
requested = [] // reset requested list
}
lastLoadedBoard = ch
if (document.getElementById('none') !== null){
document.getElementById('none').remove();
}
var feedText = httpGet('/flow/getpostsbyboard/' + ch)
var blockList = feedText.split(',')
for (i = 0; i < blockList.length; i++){
while (blockList[i].length < 64) { blockList[i] = "0" + blockList[i] }
if (! requested.includes(blockList[i])){
if (blockList[i].length == 0){
continue
}
requested.push(blockList[i])
loadMessage(blockList[i], blockList, i)
}
}
}
function loadMessage(blockHash, blockList, count){
fetch('/getblockdata/' + blockHash, {
method: 'GET',
headers: {
"token": webpass
}})
.then((resp) => resp.json())
.then(function(data) {
let before = blockList[count - 1]
let delay = 2000
if (typeof before == "undefined"){
before = null
}
else{
let existing = document.getElementsByClassName('cMsgBox')
for (x = 0; x < existing.length; x++){
if (existing[x].getAttribute('data-bl') === before){
delay = 0
}
}
}
setTimeout(function(){appendMessages(data, blockHash, before)}, delay)
//appendMessages(data, blockHash, before)
})
}
document.getElementById('refreshFeed').onclick = function(){
getBlocks()
}
newPostForm.onsubmit = function(){
var message = document.getElementById('newMsgText').value
var channel = document.getElementById('feedIDInput').value
var meta = {'ch': channel}
let doSign = document.getElementById('postAnon').checked
var postData = {'message': message, 'sign': doSign, 'type': 'brd', 'encrypt': false, 'meta': JSON.stringify(meta)}
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'
if (data == 'failure due to duplicate insert'){
PNotify.error({
text: "This message is already queued"
})
return
}
PNotify.success({
text: "Message queued for posting"
})
setTimeout(function(){getBlocks()}, 500)
})
return false
}

159
static-data/www/board/index.html Executable file
View file

@ -0,0 +1,159 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset='utf-8'>
<!--Mobile responsive-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
Circles
</title>
<link rel='shortcut icon' type='image/ico' href='/shared/images/favicon.ico'>
<link rel='stylesheet' href='/shared/main/PNotifyBrightTheme.css'>
<link rel="stylesheet" href="/shared/fontawesome-free-5.10.2/css/all.min.css">
<link rel='stylesheet' href='/shared/main/bulma.min.css'>
<link rel="stylesheet" href='/shared/main/styles-new.css'>
<link rel="stylesheet" href="theme.css">
<script defer src="/shared/base32.js"></script>
<script defer src="/shared/identicon.js"></script>
<script defer src='/shared/node_modules/pnotify/dist/iife/PNotify.js'></script>
<script defer src='/shared/node_modules/pnotify/dist/iife/PNotifyButtons.js'></script>
<script defer src='/shared/navbar.js'></script>
<script defer src="/shared/useridenticons.js"></script>
<script defer src='/shared/misc.js'></script>
<script defer src='sethumanreadable.js'></script>
<script defer src='board.js'></script>
<script defer src='autorefresh.js'></script>
</head>
<body>
<nav class="navbar is-dark" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item idLink" href="/">
<img src="/shared/images/favicon.ico" class="navbarLogo"> Onionr
</a>
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false"
data-target="navbarBasicExample">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item idLink" href="/">Home</a>
<a class="navbar-item idLink" href="/mail/">Mail</a>
<a class="navbar-item idLink" href="/friends/">Friends</a>
<a class="navbar-item idLink" href="/board/">Circles</a>
<a class="navbar-item idLink" href="/chat/">Chat</a>
</div>
</div>
</nav>
<!--Hero (Dark Section)-->
<section class="hero is-small is-dark">
<div class="hero-body">
<div class="container">
<div class="columns">
<div class="column">
<h1 class="title">
Circles <span class="is-pulled-right">v<span id='circlesVersion'></span></span>
</h1>
<h2 class="subtitle">
Anonymous message boards
</h2>
</div>
</div>
</div>
</section>
<br>
<!--Start Content-->
<div class="container">
<div class="columns">
<!--Add Friend-->
<div class="column is-one-third">
<div class="card">
<form method='POST' action='/' id='addMsg'>
<header class="card-header">
<p class="card-header-title">
Post message
</p>
</header>
<div class="card-content">
<div class="content">
<textarea id='newMsgText' class="textarea" name='newMsgText' rows=10 cols=50 required
minlength="2"></textarea>
</div>
</div>
<footer class="card-footer">
<a class="card-footer-item">
<input class='button is-primary' type='submit' value='Post'>
</a>
</footer>
</form>
</div>
</div>
<!--Feed-->
<div class="column">
<div class="card">
<header class="card-header">
<p class="card-header-title">
Feed
</p>
</header>
<div class="card-content">
<div class="content">
<div class="field">
<div class="field has-addons">
<p class="control">
<a class="button is-static">Board Name</a>
</p>
<p class="control is-expanded">
<input id='feedIDInput' class="input" placeholder="Board name" value="global">
</p>
<p class="control">
<a class="button is-success" id='refreshFeed'>Refresh Feed</a>
</p>
</div>
<input type="checkbox" class="checkbox" id="refreshCheckbox" checked>
<label for="refreshCheckbox">Auto refresh feed</label>
<br>
<input type="checkbox" class="checkbox" id="postAnon" checked>
<label for="postAnon">Sign posts</label>
</div>
</div>
<div class="content">
<span id='loadingBoard'>Loading board... <i class="fas fa-yin-yang fa-spin"></i></span>
<div id='feed'>
<span id='none'>None yet, try refreshing 😃</span>
<!--Message Items are appended here based on template-->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--Template markup for Circle message-->
<template id="cMsgTemplate">
<div class="box cMsgBox">
<div class="columns">
<div class="column cMsg">
Message
</div>
<div class="column cAuthor is-narrow"></div>
<img class="identicon image is-48x48" alt="user icon" src="/shared/images/anon.svg">
<div class="column is-narrow cMsgDate">
Date
</div>
</div>
</div>
</template>
</body>
</html>

View file

@ -0,0 +1,39 @@
/*
Onionr - Private P2P Communication
Set human readable public keys onto post author elements
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
humanReadableKeys = {}
function setHumanReadableIDOnPost(el, key){
if (typeof humanReadableKeys[key] == "undefined"){
fetch('/getHumanReadable/' + key, {
method: 'GET',
headers: {
"token": webpass
}})
.then((resp) => resp.text()) // Transform the data into json
.then(function(data) {
if (data.includes('HTML')){
return
}
humanReadableKeys[key] = data
setHumanReadableIDOnPost(el, key)
})
return
}
el.innerText = humanReadableKeys[key].split('-').slice(0, 3).join(' ')
}

View file

@ -0,0 +1,6 @@
.cMsg{
word-wrap:break-word;
word-break:break-word;
white-space: pre-wrap;
}