From 886178b79d72864000b1e1ee6ba03e2c1267651f Mon Sep 17 00:00:00 2001 From: Mystikfluu Date: Sun, 24 Apr 2022 11:56:14 +0200 Subject: [PATCH] added special text --- css/posts.css | 3 +++ js/posts.js | 16 ++++++++++++++-- server.js | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/css/posts.css b/css/posts.css index 90706b4..9874fa0 100644 --- a/css/posts.css +++ b/css/posts.css @@ -10,6 +10,9 @@ color: lightgreen; } +.specialtext { + color: yellow; +} #posts > div { background-color: darkgray; diff --git a/js/posts.js b/js/posts.js index 25a993d..570d60e 100644 --- a/js/posts.js +++ b/js/posts.js @@ -31,11 +31,17 @@ function filterPost(text) { text = filterMentions(text) return text } -function createPost(username,text,time) { +function createPost(username,text,time,specialtext) { + if(specialtext){ + specialtext = ` | ${specialtext}` + } else { + specialtext = "" + } const newDiv = document.createElement("div"); const newP = document.createElement("p"); const newSpan = document.createElement("span"); const newSpan2 = document.createElement("span"); + const newSpan3 = document.createElement("span"); //const newText = document.createTextNode(text); @@ -47,12 +53,18 @@ function createPost(username,text,time) { 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") + newSpan.appendChild(newUsername) newSpan2.appendChild(newTime) + newSpan3.appendChild(newSpecialText) newP.appendChild(newSpan) newP.appendChild(newSpan2) + newP.appendChild(newSpan3) newDiv.appendChild(newP) @@ -75,7 +87,7 @@ async function main() { document.getElementById("posts").innerHTML = "" last_10_posts.forEach((item, i) => { console.log(item,i); - createPost(item.post_user_name,item.post_text,item.post_time) + createPost(item.post_user_name,item.post_text,item.post_time,item.post_special_text) }); let mentions = document.getElementsByClassName("mention") for (let i = 0; i < mentions.length; i++) { diff --git a/server.js b/server.js index 9d80dc8..d242c21 100644 --- a/server.js +++ b/server.js @@ -265,7 +265,7 @@ router.post("/api/post", async function(req,res) { router.get("/api/getPosts/*", async function(req,res) { - let sql = `select post_user_name,post_text,post_time from zerotwohub.posts where post_id >= ? and post_id <= ? order by post_id desc;` + let sql = `select post_user_name,post_text,post_time,post_special_text from zerotwohub.posts where post_id >= ? and post_id <= ? order by post_id desc;` let id = parseInt(req.originalUrl.replace("/api/getPosts/")) if(isNaN(id))id=0 let values = [id,id+100]