From 7b852dbbcb9f711842ca1ca06431b5a2325db621 Mon Sep 17 00:00:00 2001 From: nekobit Date: Tue, 7 Jun 2022 06:58:08 +0000 Subject: [PATCH] JS reply_get_mentions FossilOrigin-Name: 8d6cc782d8149bfb3b0d223cea058c8fc7a4141f191b7d25e3280de1d87dd2cf --- dist/js/main.js | 29 +++++++++++++++++++++++++---- dist/treebird20.css | 4 ++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/dist/js/main.js b/dist/js/main.js index 319a9df..85a1501 100644 --- a/dist/js/main.js +++ b/dist/js/main.js @@ -10,7 +10,22 @@ function get_cookie(cookiestr) .split('=')[1]; } -function construct_quick_reply_form(replyid) +// TODO Check if logged in .acct value is the same +function reply_get_mentions(reply, content) +{ + const regexpr = /.*?<\/a>/g; + const arr = [...content.matchAll(regexpr)]; + let res = reply ? `@${reply} ` : ""; + const matches = content.matchAll(regexpr); + + for (let x of matches) + { + res += `@${x[1]}@${x[2]} `; + } + return res; +} + +function construct_quick_reply_form(status) { let src = document.createElement("form"); src.action = "/status/create"; @@ -20,7 +35,7 @@ function construct_quick_reply_form(replyid) let hiddeninput = document.createElement("input"); hiddeninput.type = "hidden"; hiddeninput.name = "replyid" - hiddeninput.value = replyid; + hiddeninput.value = status.id; let statusbox = document.createElement("div"); statusbox.className = "statusbox statusbox-ani"; @@ -30,6 +45,13 @@ function construct_quick_reply_form(replyid) textarea.tabindex = 1; textarea.name = "content"; + // Load placeholder text + let instance_info = status.querySelector(".instance-info"); + textarea.innerText = reply_get_mentions( + instance_info ? instance_info.innerText : null, + status.querySelector(".status-content").innerHTML + ); + let statusfooter = document.createElement("div"); statusfooter.className = "statusfooter"; let statusfooter_sides = { @@ -187,9 +209,8 @@ function create_reply_form(e) status.nextSibling.remove(); } else { - let form = construct_quick_reply_form(status.id); + let form = construct_quick_reply_form(status); form.insertAfter(status); - } diff --git a/dist/treebird20.css b/dist/treebird20.css index ad5a056..7e69aa6 100644 --- a/dist/treebird20.css +++ b/dist/treebird20.css @@ -1183,7 +1183,7 @@ p} { display: block; padding: 3px 2px 5px; - min-width: 43px; + min-width: 39px; } .view-btn @@ -1243,7 +1243,7 @@ p} .status-interact .count { - font-size: 14px; + font-size: 12px; padding-bottom: 3px; vertical-align: middle; }