fix error + format
This commit is contained in:
+2
-2
@@ -9,7 +9,7 @@ const navbar = `<ul class="navbar noselect">
|
||||
//<li><a href="/search" id="hide_search">Search</a></li>
|
||||
|
||||
function addnavbar() {
|
||||
document.body.innerHTML = navbar + document.body.innerHTML
|
||||
document.body.innerHTML = navbar + document.body.innerHTML
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", addnavbar)
|
||||
document.addEventListener('DOMContentLoaded', addnavbar)
|
||||
|
||||
+24
-15
@@ -1,22 +1,31 @@
|
||||
async function setUser() {
|
||||
let user = await (await fetch("/api/getuser")).json()
|
||||
//user["username"],user["error"]
|
||||
if(user["username"])document.getElementById("username").innerText = `Current User: ${user["username"]}`
|
||||
if(user["error"])document.getElementById("username").innerText = `Error: ${user["error"]}`
|
||||
|
||||
let user = await (await fetch('/api/getuser')).json()
|
||||
//user["username"],user["error"]
|
||||
if (user['username'])
|
||||
document.getElementById('username').innerText =
|
||||
`Current User: ${user['username']}`
|
||||
if (user['error'])
|
||||
document.getElementById('username').innerText =
|
||||
`Error: ${user['error']}`
|
||||
}
|
||||
|
||||
setUser()
|
||||
|
||||
async function changePW(){
|
||||
if(window.confirm("Are you sure that you want to change your Password?")){
|
||||
let re = await (await post("/api/changePW",{"currentPW":document.getElementById("currentPW").value,"newPW":document.getElementById("newPW").value})).json()
|
||||
document.getElementById("response").innerText = re["error"] || re["success"]
|
||||
document.getElementById("response").style="color:green"
|
||||
if(re["error"]) {
|
||||
document.getElementById("response").style="color:red"
|
||||
async function changePW() {
|
||||
if (window.confirm('Are you sure that you want to change your Password?')) {
|
||||
let re = await (
|
||||
await post('/api/changePW', {
|
||||
currentPW: document.getElementById('currentPW').value,
|
||||
newPW: document.getElementById('newPW').value,
|
||||
})
|
||||
).json()
|
||||
document.getElementById('response').innerText =
|
||||
re['error'] || re['success']
|
||||
document.getElementById('response').style = 'color:green'
|
||||
if (re['error']) {
|
||||
document.getElementById('response').style = 'color:red'
|
||||
}
|
||||
document.getElementById('currentPW').value = ''
|
||||
document.getElementById('newPW').value = ''
|
||||
}
|
||||
document.getElementById("currentPW").value = ""
|
||||
document.getElementById("newPW").value = ""
|
||||
}
|
||||
}
|
||||
|
||||
+28
-17
@@ -1,25 +1,36 @@
|
||||
async function setUser() {
|
||||
let user = await (await fetch("/api/getuser")).json()
|
||||
//user["username"],user["error"]
|
||||
if(user["username"])document.getElementById("username").innerText = `Current User: ${user["username"]}`
|
||||
if(user["error"])document.getElementById("username").innerText = `Error: ${user["error"]}`
|
||||
|
||||
let user = await (await fetch('/api/getuser')).json()
|
||||
//user["username"],user["error"]
|
||||
if (user['username'])
|
||||
document.getElementById('username').innerText =
|
||||
`Current User: ${user['username']}`
|
||||
if (user['error'])
|
||||
document.getElementById('username').innerText =
|
||||
`Error: ${user['error']}`
|
||||
}
|
||||
|
||||
setUser()
|
||||
|
||||
async function change(){
|
||||
if(window.confirm("Are you sure that you want to change your Username?")){
|
||||
let re = await (await post("/api/changeUsername",{"currentPW":document.getElementById("currentPW").value.toString(),"newUsername":document.getElementById("newUsername").value})).json()
|
||||
document.getElementById("response").innerText = re["error"] || re["success"]
|
||||
document.getElementById("response").style="color:green"
|
||||
if(re["error"]) {
|
||||
document.getElementById("response").style="color:red"
|
||||
async function change() {
|
||||
if (window.confirm('Are you sure that you want to change your Username?')) {
|
||||
let re = await (
|
||||
await post('/api/changeUsername', {
|
||||
currentPW: document
|
||||
.getElementById('currentPW')
|
||||
.value.toString(),
|
||||
newUsername: document.getElementById('newUsername').value,
|
||||
})
|
||||
).json()
|
||||
document.getElementById('response').innerText =
|
||||
re['error'] || re['success']
|
||||
document.getElementById('response').style = 'color:green'
|
||||
if (re['error']) {
|
||||
document.getElementById('response').style = 'color:red'
|
||||
}
|
||||
document.getElementById('currentPW').value = ''
|
||||
document.getElementById('newUsername').value = ''
|
||||
setUser()
|
||||
}
|
||||
document.getElementById("currentPW").value = ""
|
||||
document.getElementById("newUsername").value = ""
|
||||
setUser()
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById("submit").addEventListener("click",change)
|
||||
document.getElementById('submit').addEventListener('click', change)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
let username
|
||||
|
||||
const wss_server = "wss://ipost.rocks"
|
||||
const wss_port = "443"
|
||||
const wss_URI = wss_server + ":" + wss_port
|
||||
const wss_server = 'wss://ipost.rocks'
|
||||
const wss_port = '443'
|
||||
const wss_URI = wss_server + ':' + wss_port
|
||||
|
||||
var reply_id = 0
|
||||
|
||||
@@ -10,51 +10,51 @@ var highest_id
|
||||
|
||||
var currentChannel
|
||||
|
||||
let socket = new WebSocket(wss_URI);
|
||||
socket.addEventListener("message", async function (_event) {
|
||||
console.info("TODO: add websocket support to dms")
|
||||
// return
|
||||
// if(wss_server === event.origin) {
|
||||
// let data = event.data;
|
||||
// let ds = JSON.parse(data)
|
||||
// let message = ds.message
|
||||
// let item = ds.data
|
||||
// let username = decodeURIComponent(item.post_user_name)
|
||||
// if(message === "new_post") {
|
||||
// await createPost(decodeURIComponent(item.post_user_name),decodeURIComponent(item.post_text),item.post_time,item.post_special_text,highest_id+1,item.post_from_bot,item.post_reply_id,true)
|
||||
// if(user["username"]!==username)mainNoti(username)
|
||||
let socket = new WebSocket(wss_URI)
|
||||
socket.addEventListener('message', async function (_event) {
|
||||
console.info('TODO: add websocket support to dms')
|
||||
// return
|
||||
// if(wss_server === event.origin) {
|
||||
// let data = event.data;
|
||||
// let ds = JSON.parse(data)
|
||||
// let message = ds.message
|
||||
// let item = ds.data
|
||||
// let username = decodeURIComponent(item.post_user_name)
|
||||
// if(message === "new_post") {
|
||||
// await createPost(decodeURIComponent(item.post_user_name),decodeURIComponent(item.post_text),item.post_time,item.post_special_text,highest_id+1,item.post_from_bot,item.post_reply_id,true)
|
||||
// if(user["username"]!==username)mainNoti(username)
|
||||
|
||||
// let highest_known_posts = await (await fetch(`/api/getPostsLowerThan?id=${highest_id+28}&channel=${currentChannel}`)).json()
|
||||
// for (let i = 0; i < highest_known_posts.length; i++) {
|
||||
// if(document.getElementById(highest_known_posts[i].post_id) === undefined) {
|
||||
// main()
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// highest_id++;
|
||||
// }
|
||||
// }
|
||||
// let highest_known_posts = await (await fetch(`/api/getPostsLowerThan?id=${highest_id+28}&channel=${currentChannel}`)).json()
|
||||
// for (let i = 0; i < highest_known_posts.length; i++) {
|
||||
// if(document.getElementById(highest_known_posts[i].post_id) === undefined) {
|
||||
// main()
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// highest_id++;
|
||||
// }
|
||||
// }
|
||||
})
|
||||
|
||||
var cd = true //inversed "cooldown"
|
||||
|
||||
let encryption_keys = ""
|
||||
let encryption_keys = ''
|
||||
|
||||
function set_keys(s_key) {
|
||||
let key = extend(s_key,512)
|
||||
let msgkey = key.substring(0,128)
|
||||
let sigkey = key.substring(129,512)
|
||||
let key = extend(s_key, 512)
|
||||
let msgkey = key.substring(0, 128)
|
||||
let sigkey = key.substring(129, 512)
|
||||
|
||||
let packed = pack_keys({
|
||||
signkey: sigkey,
|
||||
messagekey: msgkey
|
||||
})
|
||||
let packed = pack_keys({
|
||||
signkey: sigkey,
|
||||
messagekey: msgkey,
|
||||
})
|
||||
|
||||
localStorage.setItem(currentChannel+"enc_key",packed)
|
||||
|
||||
encryption_keys = packed
|
||||
localStorage.setItem(currentChannel + 'enc_key', packed)
|
||||
|
||||
main()
|
||||
encryption_keys = packed
|
||||
|
||||
main()
|
||||
}
|
||||
|
||||
let last_called_postMsg = Date.now()
|
||||
@@ -63,424 +63,487 @@ let last_called_postMsg = Date.now()
|
||||
previously called postMessage
|
||||
*/
|
||||
async function postMsg() {
|
||||
if((Date.now() - last_called_postMsg) < 100) {
|
||||
createModal("slow down there")
|
||||
debugger;
|
||||
return;
|
||||
}
|
||||
last_called_postMsg = Date.now()
|
||||
let len = document.getElementById("post-text").value.length
|
||||
if(len >= 1001) {
|
||||
alert(`Your message cant contain more than 1000 characters! (${len})`)
|
||||
return
|
||||
}
|
||||
if(cd && posting_id!==undefined) {
|
||||
cd = false
|
||||
|
||||
let text = document.getElementById("post-text").value
|
||||
|
||||
if(typeof encrypt === "function" && encryption_keys !== "") {
|
||||
text = encrypt(text,{
|
||||
packed: encryption_keys
|
||||
})
|
||||
if (Date.now() - last_called_postMsg < 100) {
|
||||
createModal('slow down there')
|
||||
debugger
|
||||
return
|
||||
}
|
||||
last_called_postMsg = Date.now()
|
||||
let len = document.getElementById('post-text').value.length
|
||||
if (len >= 1001) {
|
||||
alert(`Your message cant contain more than 1000 characters! (${len})`)
|
||||
return
|
||||
}
|
||||
if (cd && posting_id !== undefined) {
|
||||
cd = false
|
||||
|
||||
let r = await post("/api/dms/post",{"message":text,"reply_id":reply_id,"receiver":currentChannel,"pid": posting_id})
|
||||
update_pid()
|
||||
if(window.location.href.split("?mention=")[1])location.replace('/posts');
|
||||
document.getElementById("post-text").value=""
|
||||
unreply()
|
||||
setTimeout(function(){
|
||||
cd = true
|
||||
},200)
|
||||
} else {
|
||||
alert("Please wait a tiny bit before posting again")
|
||||
}
|
||||
let text = document.getElementById('post-text').value
|
||||
|
||||
if (typeof encrypt === 'function' && encryption_keys !== '') {
|
||||
text = encrypt(text, {
|
||||
packed: encryption_keys,
|
||||
})
|
||||
}
|
||||
|
||||
let r = await post('/api/dms/post', {
|
||||
message: text,
|
||||
reply_id: reply_id,
|
||||
receiver: currentChannel,
|
||||
pid: posting_id,
|
||||
})
|
||||
update_pid()
|
||||
if (window.location.href.split('?mention=')[1])
|
||||
location.replace('/posts')
|
||||
document.getElementById('post-text').value = ''
|
||||
unreply()
|
||||
setTimeout(function () {
|
||||
cd = true
|
||||
}, 200)
|
||||
} else {
|
||||
alert('Please wait a tiny bit before posting again')
|
||||
}
|
||||
}
|
||||
|
||||
async function update_pid() {
|
||||
let r = await (await fetch("/api/dms/pid")).json()
|
||||
console.log("new pid info: ",r)
|
||||
if(r.error) {
|
||||
//an error occurred
|
||||
if(r.error === "you cannot access the api without being logged in") {
|
||||
//account error, go to login page
|
||||
location.replace("/")
|
||||
return
|
||||
let r = await (await fetch('/api/dms/pid')).json()
|
||||
console.log('new pid info: ', r)
|
||||
if (r.error) {
|
||||
//an error occurred
|
||||
if (r.error === 'you cannot access the api without being logged in') {
|
||||
//account error, go to login page
|
||||
location.replace('/')
|
||||
return
|
||||
}
|
||||
|
||||
//possibly more errors coming soon :tm: ?
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//possibly more errors coming soon :tm: ?
|
||||
|
||||
|
||||
return
|
||||
}
|
||||
posting_id = r.pid
|
||||
console.log("Updated pid",posting_id)
|
||||
posting_id = r.pid
|
||||
console.log('Updated pid', posting_id)
|
||||
}
|
||||
|
||||
function spacerTextNode() {
|
||||
return document.createTextNode(" | ")
|
||||
return document.createTextNode(' | ')
|
||||
}
|
||||
|
||||
const user_cache = {}
|
||||
async function getavatar(username) {
|
||||
let user = user_cache[username]
|
||||
if(user === undefined) {
|
||||
user = (await (await fetch("/api/getotheruser?user="+encodeURIComponent(username))).json())["avatar"]
|
||||
if(user) {
|
||||
user = "/avatars/"+user
|
||||
let user = user_cache[username]
|
||||
if (user === undefined) {
|
||||
user = (
|
||||
await (
|
||||
await fetch(
|
||||
'/api/getotheruser?user=' + encodeURIComponent(username)
|
||||
)
|
||||
).json()
|
||||
)['avatar']
|
||||
if (user) {
|
||||
user = '/avatars/' + user
|
||||
} else {
|
||||
user = '/images/default_avatar.png'
|
||||
}
|
||||
user_cache[username] = user
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
async function reply_link_clicked(reply_channel, reply_id) {
|
||||
console.log('clicked link')
|
||||
if (reply_channel !== currentChannel) {
|
||||
console.log('reply is in another channel')
|
||||
switchChannel(reply_channel)
|
||||
console.log('switched channel')
|
||||
await main()
|
||||
console.log('loaded new messages')
|
||||
let replied_msg = document.getElementById(reply_id)
|
||||
if (replied_msg) {
|
||||
console.log('found element')
|
||||
replied_msg.scrollIntoView()
|
||||
}
|
||||
} else {
|
||||
user = "/images/default_avatar.png"
|
||||
let replied_msg = document.getElementById(reply_id)
|
||||
if (replied_msg) {
|
||||
console.log('found element')
|
||||
replied_msg.scrollIntoView()
|
||||
}
|
||||
}
|
||||
user_cache[username]=user
|
||||
}
|
||||
return user
|
||||
}
|
||||
|
||||
async function reply_link_clicked(reply_channel,reply_id) {
|
||||
console.log("clicked link")
|
||||
if(reply_channel !== currentChannel) {
|
||||
console.log("reply is in another channel")
|
||||
switchChannel(reply_channel)
|
||||
console.log("switched channel")
|
||||
await main()
|
||||
console.log("loaded new messages")
|
||||
let replied_msg = document.getElementById(reply_id)
|
||||
if(replied_msg) {
|
||||
console.log("found element")
|
||||
replied_msg.scrollIntoView()
|
||||
}
|
||||
} else {
|
||||
let replied_msg = document.getElementById(reply_id)
|
||||
if(replied_msg) {
|
||||
console.log("found element")
|
||||
replied_msg.scrollIntoView()
|
||||
}
|
||||
}
|
||||
}
|
||||
async function createPost(
|
||||
username,
|
||||
text,
|
||||
time,
|
||||
specialtext,
|
||||
postid,
|
||||
isbot,
|
||||
reply_id,
|
||||
add_on_top
|
||||
) {
|
||||
if (!specialtext) specialtext = ''
|
||||
const newDiv = document.createElement('div')
|
||||
const newP = document.createElement('p')
|
||||
const newA = document.createElement('a')
|
||||
const newSpan2 = document.createElement('span')
|
||||
const newSpan3 = document.createElement('span')
|
||||
const avatar = document.createElement('img')
|
||||
const boticon = document.createElement('img')
|
||||
|
||||
async function createPost(username,text,time,specialtext,postid,isbot,reply_id,add_on_top) {
|
||||
if(!specialtext)specialtext=""
|
||||
const newDiv = document.createElement("div");
|
||||
const newP = document.createElement("p");
|
||||
const newA = document.createElement("a");
|
||||
const newSpan2 = document.createElement("span");
|
||||
const newSpan3 = document.createElement("span");
|
||||
const avatar = document.createElement("img");
|
||||
const boticon = document.createElement("img");
|
||||
const replyDiv = document.createElement('div')
|
||||
const replyA = document.createElement('a')
|
||||
const replyAvatar = document.createElement('img')
|
||||
const replySpan = document.createElement('span')
|
||||
const replyBr = document.createElement('br')
|
||||
|
||||
const replyDiv = document.createElement("div");
|
||||
const replyA = document.createElement("a");
|
||||
const replyAvatar = document.createElement("img");
|
||||
const replySpan = document.createElement("span");
|
||||
const replyBr = document.createElement("br");
|
||||
boticon.src = '/images/bot.png'
|
||||
boticon.height = 25
|
||||
boticon.width = 25
|
||||
boticon.classList.add('boticon')
|
||||
|
||||
boticon.src = "/images/bot.png"
|
||||
boticon.height = 25
|
||||
boticon.width = 25
|
||||
boticon.classList.add("boticon")
|
||||
const newUsername = document.createTextNode(username)
|
||||
let timedate = new Date(time)
|
||||
time = timedate
|
||||
time = time.toString()
|
||||
time = time.split(' ')
|
||||
time =
|
||||
time[0] + ' ' + time[1] + ' ' + time[2] + ' ' + time[3] + ' ' + time[4]
|
||||
if (
|
||||
timedate ===
|
||||
'Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)'
|
||||
)
|
||||
time = 'unknown time'
|
||||
const newTime = document.createTextNode(time)
|
||||
const newSpecialText = document.createTextNode(specialtext)
|
||||
newDiv.classList.add('post')
|
||||
newSpan3.classList.add('specialtext')
|
||||
|
||||
const newUsername = document.createTextNode(username);
|
||||
let timedate = new Date(time)
|
||||
time = timedate
|
||||
time = time.toString()
|
||||
time = time.split(" ")
|
||||
time = time[0] + " " + time[1] + " " + time[2] + " " + time[3] + " " + time[4]
|
||||
if(timedate==="Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)")time="unknown time"
|
||||
const newTime = document.createTextNode(time)
|
||||
const newSpecialText = document.createTextNode(specialtext)
|
||||
newDiv.classList.add("post");
|
||||
newSpan3.classList.add("specialtext")
|
||||
avatar.width = 25
|
||||
avatar.height = 25
|
||||
avatar.classList.add('avatar')
|
||||
|
||||
avatar.src = await getavatar(username)
|
||||
|
||||
avatar.width=25;
|
||||
avatar.height=25;
|
||||
avatar.classList.add("avatar")
|
||||
newA.appendChild(avatar)
|
||||
newA.appendChild(newUsername)
|
||||
|
||||
avatar.src = await getavatar(username)
|
||||
newA.href = `/users/${username}`
|
||||
newSpan2.appendChild(newTime)
|
||||
newSpan3.appendChild(newSpecialText)
|
||||
|
||||
newA.appendChild(avatar)
|
||||
newA.appendChild(newUsername)
|
||||
|
||||
newA.href = `/users/${username}`
|
||||
newSpan2.appendChild(newTime)
|
||||
newSpan3.appendChild(newSpecialText)
|
||||
|
||||
|
||||
newP.appendChild(newA)
|
||||
newP.appendChild(spacerTextNode())
|
||||
newP.appendChild(newSpan2)
|
||||
if(specialtext !== "")newP.appendChild(spacerTextNode())
|
||||
newP.appendChild(newSpan3)
|
||||
if(isbot===1){
|
||||
newP.appendChild(newA)
|
||||
newP.appendChild(spacerTextNode())
|
||||
newP.appendChild(boticon)
|
||||
}
|
||||
newP.appendChild(spacerTextNode())
|
||||
// |\>.</|
|
||||
newP.innerHTML += `<button onclick="reply(${postid})">Reply to this Post</button>`
|
||||
|
||||
if(reply_id !== 0) {
|
||||
try {
|
||||
const reply_obj = await (await fetch(`/api/dms/getDM?id=${reply_id}`)).json()
|
||||
const reply_username = decodeURIComponent(reply_obj.dms_user_name)
|
||||
const reply_username_text = document.createTextNode(reply_username)
|
||||
let reply_text = decodeURIComponent(reply_obj.dms_text)
|
||||
const reply_channel = reply_obj.dms_receiver
|
||||
replyAvatar.width=10;
|
||||
replyAvatar.height=10;
|
||||
replyAvatar.classList.add("avatar")
|
||||
replyAvatar.src = await getavatar(reply_username)
|
||||
|
||||
replyA.appendChild(replyAvatar)
|
||||
replyA.appendChild(reply_username_text)
|
||||
replyA.appendChild(spacerTextNode())
|
||||
|
||||
if(typeof decrypt === "function" && encryption_keys !== "") {
|
||||
reply_text = decrypt(reply_text,{packed:encryption_keys}).msg
|
||||
}
|
||||
|
||||
replyA.innerHTML += filterReply(reply_text.replace("\n"," ").substring(0,20))
|
||||
replyA.appendChild(replyBr)
|
||||
|
||||
replyA.classList.add("no-link-style")
|
||||
// async function onclick(event) {
|
||||
// event.preventDefault()
|
||||
|
||||
// }
|
||||
// replyDiv.onclick = function() {
|
||||
// reply_link_clicked(reply_channel, reply_id)
|
||||
// }
|
||||
|
||||
replyDiv.appendChild(replyA)
|
||||
|
||||
newDiv.appendChild(replyDiv)
|
||||
|
||||
replyDiv.outerHTML = replyDiv.outerHTML.replace(/\>/im,` onclick="reply_link_clicked('${reply_channel}',${reply_id})" \>`)
|
||||
} catch (ignored) {
|
||||
console.log(ignored)
|
||||
newP.appendChild(newSpan2)
|
||||
if (specialtext !== '') newP.appendChild(spacerTextNode())
|
||||
newP.appendChild(newSpan3)
|
||||
if (isbot === 1) {
|
||||
newP.appendChild(spacerTextNode())
|
||||
newP.appendChild(boticon)
|
||||
}
|
||||
}
|
||||
newP.appendChild(spacerTextNode())
|
||||
// |\>.</|
|
||||
newP.innerHTML += `<button onclick="reply(${postid})">Reply to this Post</button>`
|
||||
|
||||
if(typeof decrypt === "function" && encryption_keys !== "") {
|
||||
text = decrypt(text,{packed:encryption_keys}).msg
|
||||
}
|
||||
newDiv.appendChild(newP)
|
||||
newDiv.innerHTML += filterPost(text)
|
||||
newDiv.id = postid
|
||||
let posts_div = document.getElementById("posts")
|
||||
if(add_on_top) {
|
||||
posts_div.insertBefore(newDiv, posts_div.children[0]);
|
||||
} else {
|
||||
posts_div.appendChild(newDiv)
|
||||
}
|
||||
if (reply_id !== 0) {
|
||||
try {
|
||||
const reply_obj = await (
|
||||
await fetch(`/api/dms/getDM?id=${reply_id}`)
|
||||
).json()
|
||||
const reply_username = decodeURIComponent(reply_obj.dms_user_name)
|
||||
const reply_username_text = document.createTextNode(reply_username)
|
||||
let reply_text = decodeURIComponent(reply_obj.dms_text)
|
||||
const reply_channel = reply_obj.dms_receiver
|
||||
replyAvatar.width = 10
|
||||
replyAvatar.height = 10
|
||||
replyAvatar.classList.add('avatar')
|
||||
replyAvatar.src = await getavatar(reply_username)
|
||||
|
||||
replyA.appendChild(replyAvatar)
|
||||
replyA.appendChild(reply_username_text)
|
||||
replyA.appendChild(spacerTextNode())
|
||||
|
||||
if (typeof decrypt === 'function' && encryption_keys !== '') {
|
||||
reply_text = decrypt(reply_text, {
|
||||
packed: encryption_keys,
|
||||
}).msg
|
||||
}
|
||||
|
||||
replyA.innerHTML += filterReply(
|
||||
reply_text.replace('\n', ' ').substring(0, 20)
|
||||
)
|
||||
replyA.appendChild(replyBr)
|
||||
|
||||
replyA.classList.add('no-link-style')
|
||||
// async function onclick(event) {
|
||||
// event.preventDefault()
|
||||
|
||||
// }
|
||||
// replyDiv.onclick = function() {
|
||||
// reply_link_clicked(reply_channel, reply_id)
|
||||
// }
|
||||
|
||||
replyDiv.appendChild(replyA)
|
||||
|
||||
newDiv.appendChild(replyDiv)
|
||||
|
||||
replyDiv.outerHTML = replyDiv.outerHTML.replace(
|
||||
/\>/im,
|
||||
` onclick="reply_link_clicked('${reply_channel}',${reply_id})" \>`
|
||||
)
|
||||
} catch (ignored) {
|
||||
console.log(ignored)
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof decrypt === 'function' && encryption_keys !== '') {
|
||||
text = decrypt(text, { packed: encryption_keys }).msg
|
||||
}
|
||||
newDiv.appendChild(newP)
|
||||
newDiv.innerHTML += filterPost(text)
|
||||
newDiv.id = postid
|
||||
let posts_div = document.getElementById('posts')
|
||||
if (add_on_top) {
|
||||
posts_div.insertBefore(newDiv, posts_div.children[0])
|
||||
} else {
|
||||
posts_div.appendChild(newDiv)
|
||||
}
|
||||
}
|
||||
|
||||
async function main(){
|
||||
if(!user){
|
||||
user = await (await fetch("/api/getuser")).json()
|
||||
async function main() {
|
||||
if (!user) {
|
||||
user = await (await fetch('/api/getuser')).json()
|
||||
username = user.username
|
||||
if (!username) {
|
||||
user = undefined
|
||||
document.getElementById('noaccount').style = ''
|
||||
document.getElementById('loading').style = 'display:none;'
|
||||
console.log('no account')
|
||||
return
|
||||
}
|
||||
}
|
||||
username = user.username
|
||||
if(!username){
|
||||
user = undefined
|
||||
document.getElementById("noaccount").style=""
|
||||
document.getElementById("loading").style="display:none;"
|
||||
console.log("no account");
|
||||
return;
|
||||
document.getElementById('username-self').innerText = username
|
||||
|
||||
let all_posts = await (
|
||||
await fetch(`/api/getPersonalPosts?otherperson=${currentChannel}`)
|
||||
).json()
|
||||
if (!all_posts) {
|
||||
document.getElementById('loading').style = 'display:none;'
|
||||
document.getElementById('scriptonly').style = ''
|
||||
}
|
||||
}
|
||||
username = user.username
|
||||
document.getElementById("username-self").innerText = username
|
||||
|
||||
let all_posts = await (await fetch(`/api/getPersonalPosts?otherperson=${currentChannel}`)).json()
|
||||
if(!all_posts){
|
||||
document.getElementById("loading").style="display:none;"
|
||||
document.getElementById("scriptonly").style = ""
|
||||
};
|
||||
document.getElementById("posts").innerHTML = ""
|
||||
if(all_posts.length <= 0) {
|
||||
document.getElementById("loading").style="display:none;"
|
||||
document.getElementById("scriptonly").style = ""
|
||||
//TODO: empty page
|
||||
return
|
||||
}
|
||||
highest_id = all_posts[0].post_id
|
||||
for(i in all_posts) {
|
||||
let item = all_posts[i]
|
||||
await createPost(decodeURIComponent(item.dms_user_name),decodeURIComponent(item.dms_text),item.dms_time,item.dms_special_text,item.dms_id,item.dms_from_bot,item.dms_reply_id,false)
|
||||
}
|
||||
|
||||
let links = document.getElementsByClassName("insertedlink")
|
||||
for (let i = 0; i < links.length; i++) {
|
||||
links[i].innerText = links[i].innerText.split("\/\/")[1].split("\/")[0]
|
||||
}
|
||||
|
||||
let mentions = document.getElementsByClassName("mention")
|
||||
for (let i = 0; i < mentions.length; i++) {
|
||||
if(mentions[i]!==undefined && mentions[i].innerText === "@"+username) {
|
||||
mentions[i].classList.add("user-mention");
|
||||
mentions[i].classList.remove("mention");
|
||||
i--;
|
||||
document.getElementById('posts').innerHTML = ''
|
||||
if (all_posts.length <= 0) {
|
||||
document.getElementById('loading').style = 'display:none;'
|
||||
document.getElementById('scriptonly').style = ''
|
||||
//TODO: empty page
|
||||
return
|
||||
}
|
||||
highest_id = all_posts[0].post_id
|
||||
for (i in all_posts) {
|
||||
let item = all_posts[i]
|
||||
await createPost(
|
||||
decodeURIComponent(item.dms_user_name),
|
||||
decodeURIComponent(item.dms_text),
|
||||
item.dms_time,
|
||||
item.dms_special_text,
|
||||
item.dms_id,
|
||||
item.dms_from_bot,
|
||||
item.dms_reply_id,
|
||||
false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById("loading").style="display:none;"
|
||||
document.getElementById("scriptonly").style = ""
|
||||
let links = document.getElementsByClassName('insertedlink')
|
||||
for (let i = 0; i < links.length; i++) {
|
||||
links[i].innerText = links[i].innerText.split('\/\/')[1].split('\/')[0]
|
||||
}
|
||||
|
||||
let mentions = document.getElementsByClassName('mention')
|
||||
for (let i = 0; i < mentions.length; i++) {
|
||||
if (
|
||||
mentions[i] !== undefined &&
|
||||
mentions[i].innerText === '@' + username
|
||||
) {
|
||||
mentions[i].classList.add('user-mention')
|
||||
mentions[i].classList.remove('mention')
|
||||
i--
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('loading').style = 'display:none;'
|
||||
document.getElementById('scriptonly').style = ''
|
||||
}
|
||||
|
||||
async function reply(postid) {
|
||||
let post = await(await fetch("/api/dms/getDM?id="+postid)).json()
|
||||
let username = post.dms_user_name
|
||||
let posttext = post.dms_text
|
||||
document.getElementById("reply").style = ""
|
||||
document.getElementById("reply_username").innerText = decodeURIComponent(username)
|
||||
let post = await (await fetch('/api/dms/getDM?id=' + postid)).json()
|
||||
let username = post.dms_user_name
|
||||
let posttext = post.dms_text
|
||||
document.getElementById('reply').style = ''
|
||||
document.getElementById('reply_username').innerText =
|
||||
decodeURIComponent(username)
|
||||
|
||||
posttext = decodeURIComponent(posttext)
|
||||
posttext = decodeURIComponent(posttext)
|
||||
|
||||
if(typeof decrypt === "function" && encryption_keys !== "") {
|
||||
posttext = decrypt(posttext,{packed:encryption_keys}).msg
|
||||
}
|
||||
if (typeof decrypt === 'function' && encryption_keys !== '') {
|
||||
posttext = decrypt(posttext, { packed: encryption_keys }).msg
|
||||
}
|
||||
|
||||
document.getElementById("reply_text").innerHTML = filterPost(posttext)
|
||||
reply_id = postid
|
||||
document.getElementById('reply_text').innerHTML = filterPost(posttext)
|
||||
reply_id = postid
|
||||
}
|
||||
|
||||
function unreply() {
|
||||
document.getElementById("reply").style = "display:none;"
|
||||
reply_id = 0
|
||||
document.getElementById('reply').style = 'display:none;'
|
||||
reply_id = 0
|
||||
}
|
||||
|
||||
var cansendNoti = false
|
||||
|
||||
function askNotiPerms() {
|
||||
return Notification.requestPermission()
|
||||
function askNotiPerms() {
|
||||
return Notification.requestPermission()
|
||||
}
|
||||
|
||||
async function firstAsk() {
|
||||
if(Notification.permission === 'denied' || Notification.permission === 'default') {
|
||||
await askNotiPerms()
|
||||
}
|
||||
if (
|
||||
Notification.permission === 'denied' ||
|
||||
Notification.permission === 'default'
|
||||
) {
|
||||
await askNotiPerms()
|
||||
}
|
||||
}
|
||||
|
||||
async function mainNoti(user) {
|
||||
|
||||
if(Notification.permission === 'denied' || Notification.permission === 'default') {
|
||||
await askNotiPerms()
|
||||
} else {
|
||||
if(cansendNoti) {
|
||||
let notification = new Notification('IPost', { body: "new dm from " + user , tag: "new_post"});
|
||||
notification = await notification
|
||||
notification.addEventListener("click",function(){
|
||||
notification.close()
|
||||
})
|
||||
console.log(notification);
|
||||
if (
|
||||
Notification.permission === 'denied' ||
|
||||
Notification.permission === 'default'
|
||||
) {
|
||||
await askNotiPerms()
|
||||
} else {
|
||||
if (cansendNoti) {
|
||||
let notification = new Notification('IPost', {
|
||||
body: 'new dm from ' + user,
|
||||
tag: 'new_post',
|
||||
})
|
||||
notification = await notification
|
||||
notification.addEventListener('click', function () {
|
||||
notification.close()
|
||||
})
|
||||
console.log(notification)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("visibilitychange", function() {
|
||||
//cansendNoti = document.visibilityState !== 'visible'
|
||||
if (document.visibilityState === 'visible') {
|
||||
cansendNoti = false
|
||||
} else {
|
||||
cansendNoti = true
|
||||
}
|
||||
});
|
||||
document.addEventListener('visibilitychange', function () {
|
||||
//cansendNoti = document.visibilityState !== 'visible'
|
||||
if (document.visibilityState === 'visible') {
|
||||
cansendNoti = false
|
||||
} else {
|
||||
cansendNoti = true
|
||||
}
|
||||
})
|
||||
|
||||
function switchChannel(channelname) {
|
||||
sessionStorage.setItem("lastdm", channelname);
|
||||
currentChannel = channelname
|
||||
sessionStorage.setItem('lastdm', channelname)
|
||||
currentChannel = channelname
|
||||
|
||||
if(localStorage.getItem(currentChannel+"enc_key")!==null) {
|
||||
encryption_keys = localStorage.getItem(currentChannel+"enc_key")
|
||||
} else {
|
||||
encryption_keys = ""
|
||||
}
|
||||
if (localStorage.getItem(currentChannel + 'enc_key') !== null) {
|
||||
encryption_keys = localStorage.getItem(currentChannel + 'enc_key')
|
||||
} else {
|
||||
encryption_keys = ''
|
||||
}
|
||||
|
||||
try {
|
||||
socket.send(JSON.stringify({"id":"switchChannel","data":channelname}))
|
||||
} catch(err) {
|
||||
console.error(err)
|
||||
}
|
||||
try {
|
||||
socket.send(JSON.stringify({ id: 'switchChannel', data: channelname }))
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
function removeDuplicates(a) {
|
||||
let prims = {"boolean":{}, "number":{}, "string":{}}, objs = [];
|
||||
let prims = { boolean: {}, number: {}, string: {} },
|
||||
objs = []
|
||||
|
||||
return a.filter(function(item) {
|
||||
let type = typeof item;
|
||||
if(type in prims)
|
||||
return Object.prototype.hasOwnProperty.call(prims[type], item) ? false : (prims[type][item] = true);
|
||||
else
|
||||
return objs.indexOf(item) >= 0 ? false : objs.push(item);
|
||||
});
|
||||
return a.filter(function (item) {
|
||||
let type = typeof item
|
||||
if (type in prims)
|
||||
return Object.prototype.hasOwnProperty.call(prims[type], item)
|
||||
? false
|
||||
: (prims[type][item] = true)
|
||||
else return objs.indexOf(item) >= 0 ? false : objs.push(item)
|
||||
})
|
||||
}
|
||||
|
||||
function createChannel(channelname,tab) {
|
||||
channelname = decodeURIComponent(channelname)
|
||||
let channelp = document.createElement("p")
|
||||
channelp.classList.add("channel")
|
||||
channelp.id = channelname
|
||||
let textnode = document.createTextNode(channelname)
|
||||
channelp.appendChild(textnode)
|
||||
channelp.addEventListener("click", function(){
|
||||
switchChannel(channelname)
|
||||
main()
|
||||
unreply()
|
||||
})
|
||||
tab.appendChild(channelp)
|
||||
function createChannel(channelname, tab) {
|
||||
channelname = decodeURIComponent(channelname)
|
||||
let channelp = document.createElement('p')
|
||||
channelp.classList.add('channel')
|
||||
channelp.id = channelname
|
||||
let textnode = document.createTextNode(channelname)
|
||||
channelp.appendChild(textnode)
|
||||
channelp.addEventListener('click', function () {
|
||||
switchChannel(channelname)
|
||||
main()
|
||||
unreply()
|
||||
})
|
||||
tab.appendChild(channelp)
|
||||
}
|
||||
|
||||
async function loadChannels() {
|
||||
// <!-- <p class="channel">- Channel Name -</p> -->
|
||||
// <!-- <p class="channel">- Channel Name -</p> -->
|
||||
|
||||
let dms = await (await fetch("/api/dms/conversations")).json()
|
||||
let dms = await (await fetch('/api/dms/conversations')).json()
|
||||
|
||||
let channels = []
|
||||
let channels = []
|
||||
|
||||
for(let dm of dms) {
|
||||
if(dm.dms_user_name === username) {
|
||||
channels[channels.length] = dm.dms_receiver
|
||||
} else {
|
||||
channels[channels.length] = dm.dms_user_name
|
||||
}
|
||||
}
|
||||
for (let dm of dms) {
|
||||
if (dm.dms_user_name === username) {
|
||||
channels[channels.length] = dm.dms_receiver
|
||||
} else {
|
||||
channels[channels.length] = dm.dms_user_name
|
||||
}
|
||||
}
|
||||
|
||||
channels = removeDuplicates(channels)
|
||||
channels = removeDuplicates(channels)
|
||||
|
||||
let tab = document.getElementById("channelTab")
|
||||
tab.innerHTML = ""
|
||||
for (let i = 0; i < channels.length; i++) {
|
||||
if(channels[i]==="")continue;
|
||||
createChannel(channels[i],tab)
|
||||
}
|
||||
let tab = document.getElementById('channelTab')
|
||||
tab.innerHTML = ''
|
||||
for (let i = 0; i < channels.length; i++) {
|
||||
if (channels[i] === '') continue
|
||||
createChannel(channels[i], tab)
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
switchChannel(sessionStorage.getItem('lastdm') || 'none')
|
||||
|
||||
switchChannel(sessionStorage.getItem("lastdm") || "none")
|
||||
|
||||
setInterval(update_pid,30000)
|
||||
update_pid()
|
||||
main()
|
||||
firstAsk()
|
||||
loadChannels()
|
||||
setInterval(update_pid, 30000)
|
||||
update_pid()
|
||||
main()
|
||||
firstAsk()
|
||||
loadChannels()
|
||||
}
|
||||
|
||||
async function clickPress(event) {
|
||||
if (event.key === "Enter") {
|
||||
user = (await (await fetch("/api/getotheruser?user="+encodeURIComponent(document.getElementById("Username_input").value))).json())
|
||||
if(user.username === undefined) {
|
||||
alert("invalid username entered")
|
||||
return
|
||||
} else {
|
||||
if(document.getElementById(user.username) === undefined) {
|
||||
let tab = document.getElementById("channelTab")
|
||||
createChannel(encodeURIComponent(user.username),tab)
|
||||
}
|
||||
document.getElementById(user.username).click()
|
||||
document.getElementById("Username_input").value = ""
|
||||
}
|
||||
}
|
||||
if (event.key === 'Enter') {
|
||||
user = await (
|
||||
await fetch(
|
||||
'/api/getotheruser?user=' +
|
||||
encodeURIComponent(
|
||||
document.getElementById('Username_input').value
|
||||
)
|
||||
)
|
||||
).json()
|
||||
if (user.username === undefined) {
|
||||
alert('invalid username entered')
|
||||
return
|
||||
} else {
|
||||
if (document.getElementById(user.username) === undefined) {
|
||||
let tab = document.getElementById('channelTab')
|
||||
createChannel(encodeURIComponent(user.username), tab)
|
||||
}
|
||||
document.getElementById(user.username).click()
|
||||
document.getElementById('Username_input').value = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init()
|
||||
|
||||
+82
-20
@@ -1,18 +1,82 @@
|
||||
// skipqc
|
||||
var sha256=function a(b){function c(a,b){return a>>>b|a<<32-b}for(var d,e,f=Math.pow,g=f(2,32),h="length",i="",j=[],k=8*b[h],l=a.h=a.h||[],m=a.k=a.k||[],n=m[h],o={},p=2;n<64;p++)if(!o[p]){for(d=0;d<313;d+=p)o[d]=p;l[n]=f(p,.5)*g|0,m[n++]=f(p,1/3)*g|0}for(b+="\x80";b[h]%64-56;)b+="\x00";for(d=0;d<b[h];d++){if(e=b.charCodeAt(d),e>>8)return;j[d>>2]|=e<<(3-d)%4*8}for(j[j[h]]=k/g|0,j[j[h]]=k,e=0;e<j[h];){var q=j.slice(e,e+=16),r=l;for(l=l.slice(0,8),d=0;d<64;d++){var s=q[d-15],t=q[d-2],u=l[0],v=l[4],w=l[7]+(c(v,6)^c(v,11)^c(v,25))+(v&l[5]^~v&l[6])+m[d]+(q[d]=d<16?q[d]:q[d-16]+(c(s,7)^c(s,18)^s>>>3)+q[d-7]+(c(t,17)^c(t,19)^t>>>10)|0),x=(c(u,2)^c(u,13)^c(u,22))+(u&l[1]^u&l[2]^l[1]&l[2]);l=[w+x|0].concat(l),l[4]=l[4]+w|0}for(d=0;d<8;d++)l[d]=l[d]+r[d]|0}for(d=0;d<8;d++)for(e=3;e+1;e--){var y=l[d]>>8*e&255;i+=(y<16?0:"")+y.toString(16)}return i};
|
||||
|
||||
function hash(str,salt,num) {
|
||||
if(!num && num!==0)num=1;
|
||||
if(!str)return;
|
||||
if(!salt)salt=""
|
||||
let ret = str;
|
||||
for (let i = 0; i < num; i++) {
|
||||
ret = sha256(ret+salt)
|
||||
var sha256 = function a(b) {
|
||||
function c(a, b) {
|
||||
return (a >>> b) | (a << (32 - b))
|
||||
}
|
||||
return ret;
|
||||
for (
|
||||
var d,
|
||||
e,
|
||||
f = Math.pow,
|
||||
g = f(2, 32),
|
||||
h = 'length',
|
||||
i = '',
|
||||
j = [],
|
||||
k = 8 * b[h],
|
||||
l = (a.h = a.h || []),
|
||||
m = (a.k = a.k || []),
|
||||
n = m[h],
|
||||
o = {},
|
||||
p = 2;
|
||||
n < 64;
|
||||
p++
|
||||
)
|
||||
if (!o[p]) {
|
||||
for (d = 0; d < 313; d += p) o[d] = p
|
||||
;(l[n] = (f(p, 0.5) * g) | 0), (m[n++] = (f(p, 1 / 3) * g) | 0)
|
||||
}
|
||||
for (b += '\x80'; (b[h] % 64) - 56; ) b += '\x00'
|
||||
for (d = 0; d < b[h]; d++) {
|
||||
if (((e = b.charCodeAt(d)), e >> 8)) return
|
||||
j[d >> 2] |= e << (((3 - d) % 4) * 8)
|
||||
}
|
||||
for (j[j[h]] = (k / g) | 0, j[j[h]] = k, e = 0; e < j[h]; ) {
|
||||
var q = j.slice(e, (e += 16)),
|
||||
r = l
|
||||
for (l = l.slice(0, 8), d = 0; d < 64; d++) {
|
||||
var s = q[d - 15],
|
||||
t = q[d - 2],
|
||||
u = l[0],
|
||||
v = l[4],
|
||||
w =
|
||||
l[7] +
|
||||
(c(v, 6) ^ c(v, 11) ^ c(v, 25)) +
|
||||
((v & l[5]) ^ (~v & l[6])) +
|
||||
m[d] +
|
||||
(q[d] =
|
||||
d < 16
|
||||
? q[d]
|
||||
: (q[d - 16] +
|
||||
(c(s, 7) ^ c(s, 18) ^ (s >>> 3)) +
|
||||
q[d - 7] +
|
||||
(c(t, 17) ^ c(t, 19) ^ (t >>> 10))) |
|
||||
0),
|
||||
x =
|
||||
(c(u, 2) ^ c(u, 13) ^ c(u, 22)) +
|
||||
((u & l[1]) ^ (u & l[2]) ^ (l[1] & l[2]))
|
||||
;(l = [(w + x) | 0].concat(l)), (l[4] = (l[4] + w) | 0)
|
||||
}
|
||||
for (d = 0; d < 8; d++) l[d] = (l[d] + r[d]) | 0
|
||||
}
|
||||
for (d = 0; d < 8; d++)
|
||||
for (e = 3; e + 1; e--) {
|
||||
var y = (l[d] >> (8 * e)) & 255
|
||||
i += (y < 16 ? 0 : '') + y.toString(16)
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
function extend(key,len) {
|
||||
function hash(str, salt, num) {
|
||||
if (!num && num !== 0) num = 1
|
||||
if (!str) return
|
||||
if (!salt) salt = ''
|
||||
let ret = str
|
||||
for (let i = 0; i < num; i++) {
|
||||
ret = sha256(ret + salt)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
function extend(key, len) {
|
||||
let temp = []
|
||||
let out = []
|
||||
|
||||
@@ -20,18 +84,16 @@ function extend(key,len) {
|
||||
|
||||
let hashes = 0
|
||||
|
||||
for(let i=0;i<len/64;i++) {
|
||||
for (let i = 0; i < len / 64; i++) {
|
||||
temp[0] = hash(key, '', ++hashes)
|
||||
|
||||
temp[0] = hash(key,"",++hashes)
|
||||
temp[1] = hash(key, '', ++hashes)
|
||||
|
||||
temp[1] = hash(key,"",++hashes)
|
||||
temp[2] = hash(key, '', ++hashes)
|
||||
|
||||
temp[2] = hash(key,"",++hashes)
|
||||
|
||||
out[out.length] = hash(temp[0]+temp[1],temp[2],++hashes)
|
||||
out[out.length] = hash(temp[0] + temp[1], temp[2], ++hashes)
|
||||
temp = []
|
||||
|
||||
}
|
||||
|
||||
return out.join("").substring(0,len)
|
||||
}
|
||||
return out.join('').substring(0, len)
|
||||
}
|
||||
|
||||
+47
-48
@@ -1,64 +1,63 @@
|
||||
/**
|
||||
* Copyright (C) 2017-present by Andrea Giammarchi - @WebReflection
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
* Copyright (C) 2017-present by Andrea Giammarchi - @WebReflection
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
//https://github.com/WebReflection/html-escaper
|
||||
|
||||
const {replace} = '';
|
||||
const { replace } = ''
|
||||
|
||||
const es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/gi;
|
||||
const ca = /[&<>'"]/g;
|
||||
const es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/gi
|
||||
const ca = /[&<>'"]/g
|
||||
|
||||
const esca = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
"'": ''',
|
||||
'"': '"'
|
||||
};
|
||||
const pe = m => esca[m];
|
||||
|
||||
const escape = es => replace.call(es, ca, pe);
|
||||
const htmlesc = es => replace.call(es, ca, pe);
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
"'": ''',
|
||||
'"': '"',
|
||||
}
|
||||
const pe = (m) => esca[m]
|
||||
|
||||
const escape = (es) => replace.call(es, ca, pe)
|
||||
const htmlesc = (es) => replace.call(es, ca, pe)
|
||||
|
||||
const unes = {
|
||||
'&': '&',
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'>': '>',
|
||||
''': "'",
|
||||
''': "'",
|
||||
'"': '"',
|
||||
'"': '"'
|
||||
};
|
||||
const cape = m => unes[m];
|
||||
'&': '&',
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'>': '>',
|
||||
''': "'",
|
||||
''': "'",
|
||||
'"': '"',
|
||||
'"': '"',
|
||||
}
|
||||
const cape = (m) => unes[m]
|
||||
|
||||
const unescape = un => replace.call(un, es, cape);
|
||||
const unescape = (un) => replace.call(un, es, cape)
|
||||
|
||||
function escape_special(str) {
|
||||
return str.replace(/\\/g,"\\\\").replace(/`/g,"\\`");
|
||||
return str.replace(/\\/g, '\\\\').replace(/`/g, '\\`')
|
||||
}
|
||||
|
||||
function unescape_special(str) {
|
||||
return str.replace(/\\\\/g,"\\").replace(/\\`/,"`");
|
||||
return str.replace(/\\\\/g, '\\').replace(/\\`/, '`')
|
||||
}
|
||||
|
||||
+7
-1
@@ -1 +1,7 @@
|
||||
window.post = function(url, data) {return fetch(url, {method: "POST", headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)});}
|
||||
window.post = function (url, data) {
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,12 +1,12 @@
|
||||
window.addEventListener("load",async function(){
|
||||
let data = await(await fetch("/api/getuser")).json()
|
||||
if(data["username"] !== undefined) {
|
||||
document.getElementById("HasAccount").style=""
|
||||
} else {
|
||||
document.getElementById("NoAccount").style=""
|
||||
document.getElementById("hide_user").style="display:none;"
|
||||
document.getElementById("hide_posts").style="display:none;"
|
||||
document.getElementById("hide_dms").style="display:none;"
|
||||
//document.getElementById("hide_search").style="display:none;"
|
||||
}
|
||||
window.addEventListener('load', async function () {
|
||||
let data = await (await fetch('/api/getuser')).json()
|
||||
if (data['username'] !== undefined) {
|
||||
document.getElementById('HasAccount').style = ''
|
||||
} else {
|
||||
document.getElementById('NoAccount').style = ''
|
||||
document.getElementById('hide_user').style = 'display:none;'
|
||||
document.getElementById('hide_posts').style = 'display:none;'
|
||||
document.getElementById('hide_dms').style = 'display:none;'
|
||||
//document.getElementById("hide_search").style="display:none;"
|
||||
}
|
||||
})
|
||||
|
||||
+14
-14
@@ -1,21 +1,21 @@
|
||||
async function login() {
|
||||
let r = (await post("/login",{
|
||||
user: document.getElementById("user").value,
|
||||
pass: document.getElementById("pass").value,
|
||||
r: REDIRECT_URL
|
||||
}))
|
||||
if(!r.url.endsWith("/user") && !r.url.endsWith(REDIRECT_URL)) {
|
||||
document.getElementById("pass").value = ""
|
||||
console.error("login failed")
|
||||
alert("Login failed, please make sure you have the right password")
|
||||
return;
|
||||
let r = await post('/login', {
|
||||
user: document.getElementById('user').value,
|
||||
pass: document.getElementById('pass').value,
|
||||
r: REDIRECT_URL,
|
||||
})
|
||||
if (!r.url.endsWith('/user') && !r.url.endsWith(REDIRECT_URL)) {
|
||||
document.getElementById('pass').value = ''
|
||||
console.error('login failed')
|
||||
alert('Login failed, please make sure you have the right password')
|
||||
return
|
||||
}
|
||||
window.location = REDIRECT_URL || "/user"
|
||||
window.location = REDIRECT_URL || '/user'
|
||||
}
|
||||
|
||||
let passfield = document.getElementById("pass")
|
||||
let passfield = document.getElementById('pass')
|
||||
function passkeydown(e) {
|
||||
if(e.code === "Enter") {
|
||||
if (e.code === 'Enter') {
|
||||
login()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+51
-41
@@ -1,45 +1,56 @@
|
||||
const urlregex = /(([a-z]+:\/\/)(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|app|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal|tk|rocks|ga|to))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(\s+|$)/gi
|
||||
const urlregex =
|
||||
/(([a-z]+:\/\/)(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|app|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal|tk|rocks|ga|to))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(\s+|$)/gi
|
||||
function urlify(text) {
|
||||
return text.replace(urlregex,'<a href="$1" target="_blank" class="insertedlink">$1</a> ')
|
||||
return text.replace(
|
||||
urlregex,
|
||||
'<a href="$1" target="_blank" class="insertedlink">$1</a> '
|
||||
)
|
||||
}
|
||||
|
||||
const newlregex = /(\n)/gi
|
||||
function newlineify(text) {
|
||||
return text.replace(newlregex,' <br>')
|
||||
return text.replace(newlregex, ' <br>')
|
||||
}
|
||||
|
||||
const crossregex = /~([^~]*)~/gi
|
||||
function crossout(text) {
|
||||
return text.replace(crossregex,'<span class="crossout">$1</span>')
|
||||
return text.replace(crossregex, '<span class="crossout">$1</span>')
|
||||
}
|
||||
|
||||
const italicregex = /\*([^\*]*)\*/gi
|
||||
function italicify(text) {
|
||||
return text.replace(italicregex,'<i>$1</i> ')
|
||||
return text.replace(italicregex, '<i>$1</i> ')
|
||||
}
|
||||
|
||||
const boldregex = /\*\*([^\*]*)\*\*/gi
|
||||
function boldify(text) {
|
||||
return text.replace(boldregex,'<b>$1</b> ')
|
||||
return text.replace(boldregex, '<b>$1</b> ')
|
||||
}
|
||||
|
||||
const mentionregex = /@([^\s]*)/gi
|
||||
function filterMentions(text) {
|
||||
return text.replace(mentionregex,`<span><a href="/users/$1" class="mention">$1</a></span> `)
|
||||
return text.replace(
|
||||
mentionregex,
|
||||
`<span><a href="/users/$1" class="mention">$1</a></span> `
|
||||
)
|
||||
}
|
||||
|
||||
const emojiregex = /:([^:\s]*):/gi
|
||||
function emojify(text) {
|
||||
return text.replace(emojiregex,"<img class='emoji' src='/images/emoji/$1.png' alt=':$1:' title=':$1:' height=20/>")
|
||||
return text.replace(
|
||||
emojiregex,
|
||||
"<img class='emoji' src='/images/emoji/$1.png' alt=':$1:' title=':$1:' height=20/>"
|
||||
)
|
||||
}
|
||||
|
||||
function unemojify(text){
|
||||
text = text.replace(/\u{1F5FF}/gu,":moyai:")
|
||||
text = text.replace(/\u{1F440}/gu,":eyes:")
|
||||
return text
|
||||
function unemojify(text) {
|
||||
text = text.replace(/\u{1F5FF}/gu, ':moyai:')
|
||||
text = text.replace(/\u{1F440}/gu, ':eyes:')
|
||||
return text
|
||||
}
|
||||
|
||||
const allregex = /(```([^```]*)```)|(\n)|(~([^~]*)~)|(\*\*([^\*]*)\*\*)|(\*([^\*]*)\*)|(@[^\s]*)|(:([^:\s]*):)/gi
|
||||
const allregex =
|
||||
/(```([^```]*)```)|(\n)|(~([^~]*)~)|(\*\*([^\*]*)\*\*)|(\*([^\*]*)\*)|(@[^\s]*)|(:([^:\s]*):)/gi
|
||||
|
||||
const cdblregex = /```([^```]*)```/gi
|
||||
|
||||
@@ -48,29 +59,28 @@ const cdblregex = /```([^```]*)```/gi
|
||||
* @param {string} text text to filter/format
|
||||
* @return {string} html that represents the filtered text
|
||||
*/
|
||||
function filterPost(text){
|
||||
text = unemojify(text)
|
||||
let result = htmlesc(text).replace(allregex, function (match) {
|
||||
let out = match
|
||||
if(cdblregex.test(match)) {
|
||||
let paddlen = 3
|
||||
out = out.substring(paddlen,out.length-paddlen).trim()+"\n"
|
||||
out = newlineify(out)
|
||||
return `<div class="ovfl-bw"><code>${out}</code></div>`
|
||||
}
|
||||
out = newlineify(out)
|
||||
out = urlify(out)
|
||||
out = emojify(out)
|
||||
out = filterMentions(out)
|
||||
out = crossout(out)
|
||||
out = boldify(out)
|
||||
out = italicify(out)
|
||||
function filterPost(text) {
|
||||
text = unemojify(text)
|
||||
let result = htmlesc(text).replace(allregex, function (match) {
|
||||
let out = match
|
||||
if (cdblregex.test(match)) {
|
||||
let paddlen = 3
|
||||
out = out.substring(paddlen, out.length - paddlen).trim() + '\n'
|
||||
out = newlineify(out)
|
||||
return `<div class="ovfl-bw"><code>${out}</code></div>`
|
||||
}
|
||||
out = newlineify(out)
|
||||
out = urlify(out)
|
||||
out = emojify(out)
|
||||
out = filterMentions(out)
|
||||
out = crossout(out)
|
||||
out = boldify(out)
|
||||
out = italicify(out)
|
||||
|
||||
return out
|
||||
|
||||
});
|
||||
return out
|
||||
})
|
||||
|
||||
return result
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,12 +89,12 @@ function filterPost(text){
|
||||
* @return {string} html that represents the filtered text
|
||||
*/
|
||||
function filterReply(text) {
|
||||
text = htmlesc(text)
|
||||
text = newlineify(text)
|
||||
text = urlify(text)
|
||||
text = crossout(text)
|
||||
text = boldify(text)
|
||||
text = italicify(text)
|
||||
text = htmlesc(text)
|
||||
text = newlineify(text)
|
||||
text = urlify(text)
|
||||
text = crossout(text)
|
||||
text = boldify(text)
|
||||
text = italicify(text)
|
||||
|
||||
return text
|
||||
return text
|
||||
}
|
||||
|
||||
+22
-22
@@ -1,28 +1,28 @@
|
||||
function createModal(text,renderAsHTML=false) {
|
||||
if(!document.getElementById("modal")) {
|
||||
const shade = document.createElement("div")
|
||||
shade.id = "modal-shade"
|
||||
const m = document.createElement("div")
|
||||
m.id = "modal"
|
||||
const close = document.createElement("button")
|
||||
close.id = "modal-close-button"
|
||||
close.innerText = "Close"
|
||||
close.onclick = function() {
|
||||
m.style.display = shade.style.display = 'none';
|
||||
function createModal(text, renderAsHTML = false) {
|
||||
if (!document.getElementById('modal')) {
|
||||
const shade = document.createElement('div')
|
||||
shade.id = 'modal-shade'
|
||||
const m = document.createElement('div')
|
||||
m.id = 'modal'
|
||||
const close = document.createElement('button')
|
||||
close.id = 'modal-close-button'
|
||||
close.innerText = 'Close'
|
||||
close.onclick = function () {
|
||||
m.style.display = shade.style.display = 'none'
|
||||
}
|
||||
const textdiv = document.createElement("div")
|
||||
textdiv.id = "modal-text-div"
|
||||
const textdiv = document.createElement('div')
|
||||
textdiv.id = 'modal-text-div'
|
||||
m.appendChild(textdiv)
|
||||
m.appendChild(close)
|
||||
document.body.insertBefore(m,document.body.children[0])
|
||||
document.body.insertBefore(shade,document.body.children[0])
|
||||
document.body.insertBefore(m, document.body.children[0])
|
||||
document.body.insertBefore(shade, document.body.children[0])
|
||||
}
|
||||
const currentModal = document.getElementById("modal")
|
||||
const shade = document.getElementById("modal-shade")
|
||||
if(renderAsHTML) {
|
||||
document.getElementById("modal-text-div").innerHTML = text
|
||||
const currentModal = document.getElementById('modal')
|
||||
const shade = document.getElementById('modal-shade')
|
||||
if (renderAsHTML) {
|
||||
document.getElementById('modal-text-div').innerHTML = text
|
||||
} else {
|
||||
document.getElementById("modal-text-div").innerText = text
|
||||
document.getElementById('modal-text-div').innerText = text
|
||||
}
|
||||
currentModal.style.display = shade.style.display = "block"
|
||||
}
|
||||
currentModal.style.display = shade.style.display = 'block'
|
||||
}
|
||||
|
||||
+509
-450
File diff suppressed because it is too large
Load Diff
+28
-23
@@ -1,37 +1,42 @@
|
||||
async function register() {
|
||||
if(document.getElementById("pass").value.length < 10) {
|
||||
alert("Password has to be at least 10 characters long")
|
||||
return;
|
||||
if (document.getElementById('pass').value.length < 10) {
|
||||
alert('Password has to be at least 10 characters long')
|
||||
return
|
||||
}
|
||||
if(document.getElementById("user").value.length > 25) {
|
||||
alert("Username is too long!")
|
||||
return;
|
||||
if (document.getElementById('user').value.length > 25) {
|
||||
alert('Username is too long!')
|
||||
return
|
||||
}
|
||||
if(document.getElementById("user").value.search("@") !== -1) {
|
||||
if (document.getElementById('user').value.search('@') !== -1) {
|
||||
alert("User cannot contain '@' character!")
|
||||
return;
|
||||
return
|
||||
}
|
||||
let r = (await post("/register",{
|
||||
user: document.getElementById("user").value,
|
||||
pass: document.getElementById("pass").value,
|
||||
r: REDIRECT_URL
|
||||
}))
|
||||
if(!r.url.endsWith("/user?success=true") && !r.url.endsWith(REDIRECT_URL)) {
|
||||
if(r.url.endsWith("already_exists")) {
|
||||
alert("An account with that name already exists! Did you mean to login?")
|
||||
let r = await post('/register', {
|
||||
user: document.getElementById('user').value,
|
||||
pass: document.getElementById('pass').value,
|
||||
r: REDIRECT_URL,
|
||||
})
|
||||
if (
|
||||
!r.url.endsWith('/user?success=true') &&
|
||||
!r.url.endsWith(REDIRECT_URL)
|
||||
) {
|
||||
if (r.url.endsWith('already_exists')) {
|
||||
alert(
|
||||
'An account with that name already exists! Did you mean to login?'
|
||||
)
|
||||
return
|
||||
}
|
||||
//fallback
|
||||
document.getElementById("pass").value = ""
|
||||
console.error("registration failed")
|
||||
alert("Registration failed")
|
||||
return;
|
||||
document.getElementById('pass').value = ''
|
||||
console.error('registration failed')
|
||||
alert('Registration failed')
|
||||
return
|
||||
}
|
||||
window.location = REDIRECT_URL || "/user"
|
||||
window.location = REDIRECT_URL || '/user'
|
||||
}
|
||||
|
||||
function passkeydown(e) {
|
||||
if(e.code === "Enter") {
|
||||
if (e.code === 'Enter') {
|
||||
register()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+68
-53
@@ -1,10 +1,11 @@
|
||||
const valuetoText = {
|
||||
"user":"Username",
|
||||
"post":"Post"
|
||||
user: 'Username',
|
||||
post: 'Post',
|
||||
}
|
||||
|
||||
function changed() {
|
||||
document.getElementById("selector").placeholder = valuetoText[document.getElementById("type").value];
|
||||
document.getElementById('selector').placeholder =
|
||||
valuetoText[document.getElementById('type').value]
|
||||
}
|
||||
|
||||
async function getJSON(url) {
|
||||
@@ -12,69 +13,83 @@ async function getJSON(url) {
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
const type = document.getElementById("type").value
|
||||
const selector = document.getElementById("selector").value
|
||||
document.getElementById("output").innerHTML=""
|
||||
const res = await getJSON(`/api/search?type=${type}&selector=${selector}`)
|
||||
//document.getElementById("output").innerHTML = res
|
||||
console.log(res);
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
let obj = res[i]
|
||||
if(type === "user") {
|
||||
createPost(decodeURIComponent(obj.User_Name || ""),decodeURIComponent(obj.User_Bio || "wow such empty"),0)
|
||||
} else {
|
||||
createPost(decodeURIComponent(obj.post_user_name),decodeURIComponent(obj.post_text),obj.post_time,obj.post_special_text,obj.post_id)
|
||||
const type = document.getElementById('type').value
|
||||
const selector = document.getElementById('selector').value
|
||||
document.getElementById('output').innerHTML = ''
|
||||
const res = await getJSON(`/api/search?type=${type}&selector=${selector}`)
|
||||
//document.getElementById("output").innerHTML = res
|
||||
console.log(res)
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
let obj = res[i]
|
||||
if (type === 'user') {
|
||||
createPost(
|
||||
decodeURIComponent(obj.User_Name || ''),
|
||||
decodeURIComponent(obj.User_Bio || 'wow such empty'),
|
||||
0
|
||||
)
|
||||
} else {
|
||||
createPost(
|
||||
decodeURIComponent(obj.post_user_name),
|
||||
decodeURIComponent(obj.post_text),
|
||||
obj.post_time,
|
||||
obj.post_special_text,
|
||||
obj.post_id
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function keydown(event) {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault()
|
||||
submit()
|
||||
}
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault()
|
||||
submit()
|
||||
}
|
||||
}
|
||||
|
||||
function spacerTextNode() {
|
||||
return document.createTextNode(" | ")
|
||||
return document.createTextNode(' | ')
|
||||
}
|
||||
|
||||
function createPost(username,text,time,specialtext,postid) {
|
||||
if(!specialtext)specialtext=""
|
||||
const newDiv = document.createElement("div");
|
||||
const newP = document.createElement("p");
|
||||
const newA = document.createElement("a");
|
||||
const newSpan2 = document.createElement("span");
|
||||
const newSpan3 = document.createElement("span");
|
||||
function createPost(username, text, time, specialtext, postid) {
|
||||
if (!specialtext) specialtext = ''
|
||||
const newDiv = document.createElement('div')
|
||||
const newP = document.createElement('p')
|
||||
const newA = document.createElement('a')
|
||||
const newSpan2 = document.createElement('span')
|
||||
const newSpan3 = document.createElement('span')
|
||||
|
||||
const newUsername = document.createTextNode(username);
|
||||
let timedate = new Date(time)
|
||||
time = timedate
|
||||
time = time.toString()
|
||||
time = time.split(" ")
|
||||
time = time[0] + " " + time[1] + " " + time[2] + " " + time[3] + " " + time[4]
|
||||
if(timedate==="Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)")time=""
|
||||
const newTime = document.createTextNode(time)
|
||||
const newSpecialText = document.createTextNode(specialtext)
|
||||
const newUsername = document.createTextNode(username)
|
||||
let timedate = new Date(time)
|
||||
time = timedate
|
||||
time = time.toString()
|
||||
time = time.split(' ')
|
||||
time =
|
||||
time[0] + ' ' + time[1] + ' ' + time[2] + ' ' + time[3] + ' ' + time[4]
|
||||
if (
|
||||
timedate ===
|
||||
'Thu Jan 01 1970 01:00:00 GMT+0100 (Central European Standard Time)'
|
||||
)
|
||||
time = ''
|
||||
const newTime = document.createTextNode(time)
|
||||
const newSpecialText = document.createTextNode(specialtext)
|
||||
|
||||
newDiv.classList.add("result");
|
||||
newSpan3.classList.add("specialtext")
|
||||
newDiv.classList.add('result')
|
||||
newSpan3.classList.add('specialtext')
|
||||
|
||||
newA.appendChild(newUsername)
|
||||
newA.appendChild(newUsername)
|
||||
|
||||
newA.href = `/users/${username}`
|
||||
newSpan2.appendChild(newTime)
|
||||
newSpan3.appendChild(newSpecialText)
|
||||
newA.href = `/users/${username}`
|
||||
newSpan2.appendChild(newTime)
|
||||
newSpan3.appendChild(newSpecialText)
|
||||
|
||||
newP.appendChild(newA)
|
||||
if (time !== '') newP.appendChild(spacerTextNode())
|
||||
newP.appendChild(newSpan2)
|
||||
if (specialtext !== '' && time !== '') newP.appendChild(spacerTextNode())
|
||||
newP.appendChild(newSpan3)
|
||||
|
||||
newP.appendChild(newA)
|
||||
if(time !== "")newP.appendChild(spacerTextNode())
|
||||
newP.appendChild(newSpan2)
|
||||
if(specialtext !== "" && time !== "")newP.appendChild(spacerTextNode())
|
||||
newP.appendChild(newSpan3)
|
||||
|
||||
newDiv.appendChild(newP)
|
||||
newDiv.innerHTML += filterPost(text) // skipqc
|
||||
newDiv.id = postid
|
||||
document.getElementById("output").appendChild(newDiv)
|
||||
newDiv.appendChild(newP)
|
||||
newDiv.innerHTML += filterPost(text) // skipqc
|
||||
newDiv.id = postid
|
||||
document.getElementById('output').appendChild(newDiv)
|
||||
}
|
||||
|
||||
+122
-102
@@ -1,138 +1,158 @@
|
||||
function completeHandler(event) {
|
||||
console.log("completed upload");
|
||||
console.log(event.target.responseText);
|
||||
setuser() // skipqc
|
||||
console.log('completed upload')
|
||||
console.log(event.target.responseText)
|
||||
setuser() // skipqc
|
||||
}
|
||||
|
||||
function errorHandler(event) {
|
||||
console.log("error during upload");
|
||||
console.log(event.target.responseText);
|
||||
console.log('error during upload')
|
||||
console.log(event.target.responseText)
|
||||
}
|
||||
|
||||
function progressHandler(event) {
|
||||
console.log("progressing upload");
|
||||
console.log("Uploaded " + event.loaded + " bytes of " + event.total);
|
||||
console.log(event.target.responseText);
|
||||
console.log('progressing upload')
|
||||
console.log('Uploaded ' + event.loaded + ' bytes of ' + event.total)
|
||||
console.log(event.target.responseText)
|
||||
}
|
||||
|
||||
/**
|
||||
* upload avatar to the server
|
||||
* @return {undefined} no return value
|
||||
*/
|
||||
/**
|
||||
* upload avatar to the server
|
||||
* @return {undefined} no return value
|
||||
*/
|
||||
function uploadFile() {
|
||||
const file = document.getElementById("avatarUpl").files[0];
|
||||
console.log(file);
|
||||
const formdata = new FormData();
|
||||
formdata.append("avatar", file);
|
||||
const ajax = new XMLHttpRequest();
|
||||
ajax.upload.addEventListener("progress", progressHandler, false);
|
||||
ajax.addEventListener("load", completeHandler, false);
|
||||
ajax.addEventListener("error", errorHandler, false);
|
||||
ajax.addEventListener("abort", errorHandler, false);
|
||||
ajax.open("POST", "/api/setavatar");
|
||||
ajax.send(formdata);
|
||||
const file = document.getElementById('avatarUpl').files[0]
|
||||
console.log(file)
|
||||
const formdata = new FormData()
|
||||
formdata.append('avatar', file)
|
||||
const ajax = new XMLHttpRequest()
|
||||
ajax.upload.addEventListener('progress', progressHandler, false)
|
||||
ajax.addEventListener('load', completeHandler, false)
|
||||
ajax.addEventListener('error', errorHandler, false)
|
||||
ajax.addEventListener('abort', errorHandler, false)
|
||||
ajax.open('POST', '/api/setavatar')
|
||||
ajax.send(formdata)
|
||||
|
||||
document.getElementById("avatarUplButton").style = "display:none;";
|
||||
document.getElementById('avatarUplButton').style = 'display:none;'
|
||||
}
|
||||
|
||||
function logout() {
|
||||
location.assign('/logout')
|
||||
location.assign('/logout')
|
||||
}
|
||||
|
||||
async function setuser() {
|
||||
let user = await (await fetch("/api/getuser")).json();
|
||||
let username
|
||||
let bio
|
||||
let avatar
|
||||
username = user["username"];
|
||||
bio = user["bio"]
|
||||
avatar = user["avatar"]
|
||||
if(user["error"])username=user["error"];
|
||||
if(user["error"])bio=user["error"];
|
||||
if(!bio)bio="wow such empty"
|
||||
if(avatar) {
|
||||
avatar = "/avatars/"+avatar
|
||||
} else {
|
||||
avatar = "/images/default_avatar.png"
|
||||
}
|
||||
document.getElementById("user").innerText = `User: ${username}`;
|
||||
document.getElementById("bio").placeholder = decodeURIComponent(bio);
|
||||
document.getElementById("avatarimg").src = avatar;
|
||||
document.getElementById("avatarUpl").addEventListener("change", function(){
|
||||
document.getElementById("avatarUplButton").style = "";
|
||||
})
|
||||
document.getElementById("avatarUplButton").addEventListener("click",uploadFile);
|
||||
let user = await (await fetch('/api/getuser')).json()
|
||||
let username
|
||||
let bio
|
||||
let avatar
|
||||
username = user['username']
|
||||
bio = user['bio']
|
||||
avatar = user['avatar']
|
||||
if (user['error']) username = user['error']
|
||||
if (user['error']) bio = user['error']
|
||||
if (!bio) bio = 'wow such empty'
|
||||
if (avatar) {
|
||||
avatar = '/avatars/' + avatar
|
||||
} else {
|
||||
avatar = '/images/default_avatar.png'
|
||||
}
|
||||
document.getElementById('user').innerText = `User: ${username}`
|
||||
document.getElementById('bio').placeholder = decodeURIComponent(bio)
|
||||
document.getElementById('avatarimg').src = avatar
|
||||
document
|
||||
.getElementById('avatarUpl')
|
||||
.addEventListener('change', function () {
|
||||
document.getElementById('avatarUplButton').style = ''
|
||||
})
|
||||
document
|
||||
.getElementById('avatarUplButton')
|
||||
.addEventListener('click', uploadFile)
|
||||
}
|
||||
|
||||
/**
|
||||
* sets user bio
|
||||
* @param {string} str - bio to set
|
||||
* @return {promise} api response
|
||||
*/
|
||||
/**
|
||||
* sets user bio
|
||||
* @param {string} str - bio to set
|
||||
* @return {promise} api response
|
||||
*/
|
||||
function sendBio(str) {
|
||||
if(document.getElementById("bio").placeholder !== str && str !== "") {
|
||||
document.getElementById("bio").placeholder = str
|
||||
return post("/api/setBio",{"Bio":str}) // skipqc
|
||||
}
|
||||
return ""
|
||||
if (document.getElementById('bio').placeholder !== str && str !== '') {
|
||||
document.getElementById('bio').placeholder = str
|
||||
return post('/api/setBio', { Bio: str }) // skipqc
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
async function bioChanger() {
|
||||
document.getElementById("bio").disabled = !document.getElementById("bio").disabled
|
||||
document.getElementById("changeBio").innerText = (document.getElementById("bio").disabled && "Change Bio") || "Submit"
|
||||
if(document.getElementById("bio").disabled) {
|
||||
let response = await sendBio(document.getElementById("bio").value)
|
||||
console.log(response);
|
||||
document.getElementById("userstyle").innerHTML = '::placeholder {color: white;} #bio {border: 0px solid black; color:white;}'
|
||||
}
|
||||
else
|
||||
{
|
||||
document.getElementById("userstyle").innerHTML = '::placeholder {color: white;} #bio {border: 2px solid gray; color:white;}'
|
||||
}
|
||||
document.getElementById('bio').disabled =
|
||||
!document.getElementById('bio').disabled
|
||||
document.getElementById('changeBio').innerText =
|
||||
(document.getElementById('bio').disabled && 'Change Bio') || 'Submit'
|
||||
if (document.getElementById('bio').disabled) {
|
||||
let response = await sendBio(document.getElementById('bio').value)
|
||||
console.log(response)
|
||||
document.getElementById('userstyle').innerHTML =
|
||||
'::placeholder {color: white;} #bio {border: 0px solid black; color:white;}'
|
||||
} else {
|
||||
document.getElementById('userstyle').innerHTML =
|
||||
'::placeholder {color: white;} #bio {border: 2px solid gray; color:white;}'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function changePW() {
|
||||
if(window.confirm("Are you sure that you want to change your Password?")){
|
||||
let re = await (await post("/api/changePW",{"currentPW":document.getElementById("currentPW_pw").value,"newPW":document.getElementById("newPW").value})).json() // skipqc
|
||||
document.getElementById("response_pw").innerText = re["error"] || re["success"]
|
||||
document.getElementById("response_pw").style="color:green"
|
||||
if(re["error"]) {
|
||||
document.getElementById("response_pw").style="color:red"
|
||||
}
|
||||
document.getElementById("currentPW").value = ""
|
||||
document.getElementById("newPW").value = ""
|
||||
if (window.confirm('Are you sure that you want to change your Password?')) {
|
||||
let re = await (
|
||||
await post('/api/changePW', {
|
||||
currentPW: document.getElementById('currentPW_pw').value,
|
||||
newPW: document.getElementById('newPW').value,
|
||||
})
|
||||
).json() // skipqc
|
||||
document.getElementById('response_pw').innerText =
|
||||
re['error'] || re['success']
|
||||
document.getElementById('response_pw').style = 'color:green'
|
||||
if (re['error']) {
|
||||
document.getElementById('response_pw').style = 'color:red'
|
||||
}
|
||||
document.getElementById('currentPW').value = ''
|
||||
document.getElementById('newPW').value = ''
|
||||
|
||||
setuser()
|
||||
}
|
||||
setuser()
|
||||
}
|
||||
}
|
||||
|
||||
async function changeUsername() {
|
||||
if(window.confirm("Are you sure that you want to change your Username?")){
|
||||
// skipqc
|
||||
let re = await (await post("/api/changeUsername",{"currentPW":document.getElementById("currentPW_us").value.toString(),"newUsername":document.getElementById("newUsername").value})).json()
|
||||
document.getElementById("response_us").innerText = re["error"] || re["success"]
|
||||
document.getElementById("response_us").style="color:green"
|
||||
if(re["error"]) {
|
||||
document.getElementById("response_us").style="color:red"
|
||||
if (window.confirm('Are you sure that you want to change your Username?')) {
|
||||
// skipqc
|
||||
let re = await (
|
||||
await post('/api/changeUsername', {
|
||||
currentPW: document
|
||||
.getElementById('currentPW_us')
|
||||
.value.toString(),
|
||||
newUsername: document.getElementById('newUsername').value,
|
||||
})
|
||||
).json()
|
||||
document.getElementById('response_us').innerText =
|
||||
re['error'] || re['success']
|
||||
document.getElementById('response_us').style = 'color:green'
|
||||
if (re['error']) {
|
||||
document.getElementById('response_us').style = 'color:red'
|
||||
}
|
||||
document.getElementById('currentPW').value = ''
|
||||
document.getElementById('newUsername').value = ''
|
||||
setuser()
|
||||
}
|
||||
document.getElementById("currentPW").value = ""
|
||||
document.getElementById("newUsername").value = ""
|
||||
setuser()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function setAllowCCR() {
|
||||
const ACCR = document.getElementById("ACCR_checkbox").checked
|
||||
const settingname = "ACCR" //Allow Cross-Channel reply (see #22 )
|
||||
const ACCR = document.getElementById('ACCR_checkbox').checked
|
||||
const settingname = 'ACCR' //Allow Cross-Channel reply (see #22 )
|
||||
|
||||
let r = await(await post("/api/settings",{setting: settingname, value: ACCR})).json() // skipqc
|
||||
let r = await (
|
||||
await post('/api/settings', { setting: settingname, value: ACCR })
|
||||
).json() // skipqc
|
||||
|
||||
if(r.status === "error") {
|
||||
alert("Couldn't change setting")
|
||||
console.log(r.code)
|
||||
} else if(r.status === "success") {
|
||||
//changed setting
|
||||
}
|
||||
}
|
||||
if (r.status === 'error') {
|
||||
alert("Couldn't change setting")
|
||||
console.log(r.code)
|
||||
} else if (r.status === 'success') {
|
||||
//changed setting
|
||||
}
|
||||
}
|
||||
|
||||
+42
-41
@@ -1,53 +1,54 @@
|
||||
function getCookie(cname) {
|
||||
let name = cname + "=";
|
||||
let decodedCookie = decodeURIComponent(document.cookie);
|
||||
let ca = decodedCookie.split(';');
|
||||
for(let i = 0; i <ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) ===' ') {
|
||||
c = c.substring(1);
|
||||
let name = cname + '='
|
||||
let decodedCookie = decodeURIComponent(document.cookie)
|
||||
let ca = decodedCookie.split(';')
|
||||
for (let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i]
|
||||
while (c.charAt(0) === ' ') {
|
||||
c = c.substring(1)
|
||||
}
|
||||
if (c.indexOf(name) === 0) {
|
||||
return c.substring(name.length, c.length)
|
||||
}
|
||||
}
|
||||
if (c.indexOf(name) === 0) {
|
||||
return c.substring(name.length, c.length);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
return ''
|
||||
}
|
||||
|
||||
function setCookie(cname, cvalue, exdays) {
|
||||
const d = new Date();
|
||||
d.setTime(d.getTime() + (exdays*24*60*60*1000));
|
||||
let expires = "expires="+ d.toUTCString();
|
||||
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
||||
const d = new Date()
|
||||
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000)
|
||||
let expires = 'expires=' + d.toUTCString()
|
||||
document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'
|
||||
}
|
||||
|
||||
function logout() {
|
||||
localStorage.setItem("priv_key","")
|
||||
localStorage.setItem("decryption_key","")
|
||||
location.assign('/logout')
|
||||
localStorage.setItem('priv_key', '')
|
||||
localStorage.setItem('decryption_key', '')
|
||||
location.assign('/logout')
|
||||
}
|
||||
|
||||
async function setuser() {
|
||||
if(getCookie("priv_key") !== "") {
|
||||
localStorage.setItem("priv_key",getCookie("priv_key"))
|
||||
setCookie("priv_key","",0)
|
||||
}
|
||||
let user = await (await fetch("/api/getuser")).json();
|
||||
let username
|
||||
let bio
|
||||
let avatar
|
||||
username = user["username"];
|
||||
bio = user["bio"]
|
||||
avatar = user["avatar"]
|
||||
if(user["error"])username=user["error"];
|
||||
if(user["error"])bio=user["error"];
|
||||
if(!bio)bio="wow such empty"
|
||||
if(avatar) {
|
||||
avatar = "/avatars/"+avatar
|
||||
} else {
|
||||
avatar = "/images/default_avatar.png"
|
||||
}
|
||||
document.getElementById("user").innerText = `User: ${username}`;
|
||||
document.getElementById("userBio").innerText = "Bio: " + decodeURIComponent(bio);
|
||||
document.getElementById("avatarimg").src = avatar;
|
||||
if (getCookie('priv_key') !== '') {
|
||||
localStorage.setItem('priv_key', getCookie('priv_key'))
|
||||
setCookie('priv_key', '', 0)
|
||||
}
|
||||
let user = await (await fetch('/api/getuser')).json()
|
||||
let username
|
||||
let bio
|
||||
let avatar
|
||||
username = user['username']
|
||||
bio = user['bio']
|
||||
avatar = user['avatar']
|
||||
if (user['error']) username = user['error']
|
||||
if (user['error']) bio = user['error']
|
||||
if (!bio) bio = 'wow such empty'
|
||||
if (avatar) {
|
||||
avatar = '/avatars/' + avatar
|
||||
} else {
|
||||
avatar = '/images/default_avatar.png'
|
||||
}
|
||||
document.getElementById('user').innerText = `User: ${username}`
|
||||
document.getElementById('userBio').innerText =
|
||||
'Bio: ' + decodeURIComponent(bio)
|
||||
document.getElementById('avatarimg').src = avatar
|
||||
}
|
||||
|
||||
+9
-6
@@ -1,10 +1,13 @@
|
||||
const warn_messages = [
|
||||
["%cDo not paste any text in here","background: red; color: yellow; font-size: x-large"],
|
||||
["Pasting anything in here may give others access to your account."]
|
||||
[
|
||||
'%cDo not paste any text in here',
|
||||
'background: red; color: yellow; font-size: x-large',
|
||||
],
|
||||
['Pasting anything in here may give others access to your account.'],
|
||||
]
|
||||
function warnmessage() {
|
||||
for (let message of warn_messages) {
|
||||
console.log(message[0],message[1]);
|
||||
}
|
||||
for (let message of warn_messages) {
|
||||
console.log(message[0], message[1])
|
||||
}
|
||||
}
|
||||
const warn_message_int = setInterval(warnmessage,3000)
|
||||
const warn_message_int = setInterval(warnmessage, 3000)
|
||||
|
||||
Reference in New Issue
Block a user