From 90eb2628f2a77a4deeb561f4f52d3e3cdbea31df Mon Sep 17 00:00:00 2001 From: r Date: Mon, 28 Oct 2024 15:31:30 +0000 Subject: [PATCH] fluoride: Fix like/retweet for quote posts --- static/fluoride.js | 53 +++++++++++++++++++++++-------------------- templates/status.tmpl | 8 +++---- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/static/fluoride.js b/static/fluoride.js index 73d4939..d77b3ee 100644 --- a/static/fluoride.js +++ b/static/fluoride.js @@ -47,13 +47,15 @@ function updateActionForm(id, f, action) { f.dataset.action = action; } -function handleLikeForm(id, f) { +function handleLikeForm(f) { + var id = f.dataset.id; f.onsubmit = function(event) { event.preventDefault(); var action = f.dataset.action; var forms = document. - querySelectorAll(".status-"+id+" .status-like"); + querySelectorAll(".status-action-container-"+id+" .status-like"); + for (var i = 0; i < forms.length; i++) { updateActionForm(id, forms[i], reverseActions[action]); } @@ -70,7 +72,7 @@ function handleLikeForm(id, f) { if (count === 0) count = ""; var counts = document. - querySelectorAll(".status-"+id+" .status-like-count"); + querySelectorAll(".status-action-container-"+id+" .status-like-count"); for (var i = 0; i < counts.length; i++) { if (count > 0) { counts[i].innerHTML = "(" + count + ")"; @@ -88,13 +90,14 @@ function handleLikeForm(id, f) { } } -function handleRetweetForm(id, f) { +function handleRetweetForm(f) { + var id = f.dataset.id; f.onsubmit = function(event) { event.preventDefault(); var action = f.dataset.action; var forms = document. - querySelectorAll(".status-"+id+" .status-retweet"); + querySelectorAll(".status-action-container-"+id+" .status-retweet"); for (var i = 0; i < forms.length; i++) { updateActionForm(id, forms[i], reverseActions[action]); } @@ -111,7 +114,7 @@ function handleRetweetForm(id, f) { if (count === 0) count = ""; var counts = document. - querySelectorAll(".status-"+id+" .status-retweet-count"); + querySelectorAll(".status-action-container-"+id+" .status-retweet-count"); for (var i = 0; i < counts.length; i++) { if (count > 0) { counts[i].innerHTML = "(" + count + ")"; @@ -298,29 +301,29 @@ document.addEventListener("DOMContentLoaded", function() { checkCSRFToken(); checkAntiDopamineMode(); - var statuses = document.querySelectorAll(".status-container"); - for (var i = 0; i < statuses.length; i++) { - var s = statuses[i]; - var id = s.dataset.id; + var likeForms = document.querySelectorAll(".status-like"); + for (var j = 0; j < likeForms.length; j++) { + handleLikeForm(likeForms[j]); + } - var likeForm = s.querySelector(".status-like"); - handleLikeForm(id, likeForm); + var retweetForms = document.querySelectorAll(".status-retweet"); + for (var j = 0; j < retweetForms.length; j++) { + handleRetweetForm(retweetForms[j]); + } - var retweetForm = s.querySelector(".status-retweet"); - handleRetweetForm(id, retweetForm); + var replyToLinks = document.querySelectorAll(".status-reply-to-link"); + for (var j = 0; j < replyToLinks.length; j++) { + handleReplyToLink(replyToLinks[j]); + } - var replyToLink = s.querySelector(".status-reply-to-link"); - handleReplyToLink(replyToLink); + var replyLinks = document.querySelectorAll(".status-reply-link"); + for (var j = 0; j < replyLinks.length; j++) { + handleReplyLink(replyLinks[j]); + } - var replyLinks = s.querySelectorAll(".status-reply-link"); - for (var j = 0; j < replyLinks.length; j++) { - handleReplyLink(replyLinks[j]); - } - - var links = s.querySelectorAll(".status-content a"); - for (var j = 0; j < links.length; j++) { - handleStatusLink(links[j]); - } + var links = document.querySelectorAll(".status-content a"); + for (var j = 0; j < links.length; j++) { + handleStatusLink(links[j]); } var links = document.querySelectorAll(".user-profile-description a, .user-fields a"); diff --git a/templates/status.tmpl b/templates/status.tmpl index d841a93..83e210a 100644 --- a/templates/status.tmpl +++ b/templates/status.tmpl @@ -15,7 +15,7 @@ {{else}} {{block "status" (WithContext . $.Ctx)}} {{with $s := .Data}} -
+