diff --git a/html/js/comment.js b/html/js/comment.js index c7e93a4..71fd69f 100644 --- a/html/js/comment.js +++ b/html/js/comment.js @@ -1,17 +1,87 @@ -function displaycomments() { - commenting = new metaentry(undefined,"comment:",".content",{"content": -`Your comment: (no MD)
- -`}) +class comment { + constructor( comment ) { + this.selector = ".comments" + this.content = comment + + // add + // escape body (just to be sure) + newlines | author dosnt has to be escaped cuz its generated by srv (its the ip or later mby reverse dns) + comment.body = comment.body.replaceAll("<", "<").replaceAll(">", "<").replaceAll("\n","
") + + // construct time: + let date = new Date(this.content.time) + let time = String(date.getHours()).padStart(2,"0") + ":" + time += String(date.getMinutes()).padStart(2,"0") + ":" + time += String(date.getSeconds()).padStart(2,"0") + ":" + time += String(date.getMilliseconds()).padStart(3,"0") + " " + time += String(date.getDate()).padStart(2,"0") + "-" + time += String(date.getMonth()).padStart(2,"0") + "-" + time += String(date.getFullYear()) + + // construct author hover info + let authorinfo = "" + try { + authorinfo = " (" + this.content.authorinfo.country + ") " + } catch {} + + // assemble element + let elem = document.createElement("DIV") + elem.classList = ["comment"] + elem.innerHTML = ` +
+${this.content.author}${authorinfo} +wrote at ${time} +
+
+
${comment.body}
` + + $( this.selector ).append( elem ) + } + + reply() { + // WIP / planned + } } -function comment(comment) { - $.ajax({ - type: "POST", - url: "/comment", - data: { - comment: comment - }, - dataType: "json" - }) +function displaycomments() { + commenting = new metaentry(undefined, "comment:", ".content",{"content": +`Your comment: (no MD)
+ +`}) + + comments = [] + comments.push( new metaentry(undefined, "comments:", ".content", {"content": +`These comments are user generated! they are NOT (actively) moderated!`, "class":"comments"})) + + // load comments: + reloadcommenting() +} + +function reloadcommenting() { + $(".comments").html("") + fetch("/comments?post=" + postDATA.id).then(d=>d.json()).then(data=>{ + for (i in data.content) { + comments.push( new comment( data.content[i] ) ) + } + // not jank boxsizefix: + let elem = document.createElement("div") + elem.innerHTML = "." + elem.classList = ["hidden"] + $( ".comments" ).append( elem ) + }) +} + +function sendcomment(comment) { + // get ip: + let token = Math.floor( Math.random()*10**16 ) + fetch("//derzombiiie.com/getip.php?settoken=" + token, {mode: "no-cors"}).then(()=>{ + // comment + console.log(postDATA.id, comment, token) + $.post("/comments", { + post: postDATA.id, + body: comment, + ip: token + }).then( + reloadcommenting() + ) + }) } diff --git a/html/js/entry.js b/html/js/entry.js index 20c01f5..9df5fae 100644 --- a/html/js/entry.js +++ b/html/js/entry.js @@ -46,7 +46,7 @@ class metaentry { `
${this.title}

-
${this.additional.content}
+
${this.additional.content}
` element.classList = ["entrybox"] return element diff --git a/html/js/posts.js b/html/js/posts.js index b9b7dec..a85bec6 100644 --- a/html/js/posts.js +++ b/html/js/posts.js @@ -6,3 +6,4 @@ $(document).ready(() => { displayshare() displaycomments() }) + diff --git a/html/posts/index.html b/html/posts/index.html index dcebf8a..fae8552 100644 --- a/html/posts/index.html +++ b/html/posts/index.html @@ -28,4 +28,4 @@ - \ No newline at end of file + diff --git a/html/style/light.css b/html/style/light.css index 4173aa2..6b4857e 100644 --- a/html/style/light.css +++ b/html/style/light.css @@ -69,3 +69,33 @@ border-top-width: 1px; border-top-style: solid; } + +/* comments */ +.comments > .comment { + border-style: solid; + border-width: 1px; + border-color: #606060; + border-top-style: solid; + border-top-width: 0.4em; + border-top-color: #606060; +} +.comments > .comment:hover { + background-color: #60606033 +} +.comments > .comment > .authorbox > .author { + position: relative; + font-size: 1.5em; + font-family: slkscr; + color: black; +} +.comments > .comment > .authorbox > .timestamp { + font-size: 0.8em; + font-style: italic; +} +.comments > .hidden { + visibility: hidden; +} + + +/* other stuff */ + diff --git a/html/style/main.css b/html/style/main.css index 0ed3af7..709fc42 100644 --- a/html/style/main.css +++ b/html/style/main.css @@ -105,3 +105,28 @@ textarea.comment { width: calc( 100% - 0.5em); height: 5em; } + +.comments > .comment { + position: relative; + width: calc( 100% - 4em ); + left: 1em; + top: 1em; + padding-left: 0.5em; + padding-right: 0.5em; + margin-bottom: 1em; +} +.comments > .comment > .author { + position: relative; + left: 0px; +} +.comments > .comment > .seperator { + position: relative; + top: 0.2em; + height: 0px; +} +.comments > .comment > .body { + position: relative; + top: 0.5em; + margin-bottom: 1em; +} + diff --git a/node/app.js b/node/app.js index 565dc52..f278ff9 100644 --- a/node/app.js +++ b/node/app.js @@ -1,15 +1,13 @@ const fs = require("fs") const express = require("express") const fetch = require("node-fetch") +const geoip = require("geoip-ultralight") const filestuff = require("./filestuff") var con = require("./console") const JSONdb = require("simple-json-db") var posts = require("./posts") var comments = require("./comments") -//var conf = require("./config") -conf = { - "debug": true -} +var conf = require("./config") // general TODO: // config! ./config.js for some configuration in js just some form stuff @@ -58,23 +56,24 @@ con.registercmd( "comment", (arg => { break case "push": - if (!arg[1] || !arg[2] || !arg[3]) { - return console.log("Not all args specified!\nUsage: comment push