From 0d7e512a648227ff9b89d1fe4a9f66c370e7b3bd Mon Sep 17 00:00:00 2001 From: dewanakl Date: Sun, 25 Aug 2024 20:06:21 +0700 Subject: [PATCH] feat: improve code --- js/comment.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/js/comment.js b/js/comment.js index 8e6998a4..be0485d4 100644 --- a/js/comment.js +++ b/js/comment.js @@ -39,16 +39,16 @@ export const comment = (() => { owns.unset(id); document.getElementById(id).remove(); - // todo - document.querySelectorAll('[data-uuids]').forEach((n) => { + document.querySelectorAll('a[onclick="comment.showOrHide(this)"]').forEach((n) => { const oldUuids = n.getAttribute('data-uuids').split(','); if (oldUuids.find((i) => i === id)) { const uuids = oldUuids.filter((i) => i !== id).join(','); - n.setAttribute('data-uuids', uuids); - + if (uuids.length === 0) { n.remove(); + } else { + n.setAttribute('data-uuids', uuids); } } }); @@ -234,7 +234,7 @@ export const comment = (() => { anchorTag.remove(); } - containerDiv.querySelector('button.ms-auto').insertAdjacentHTML('beforebegin', card.renderReadMore(id, anchorTag ? anchorTag.getAttribute('data-uuids').split(',').concat(uuids) : uuids)); + containerDiv.querySelector(`button[onclick="like.like(this)"][data-uuid="${id}"]`).insertAdjacentHTML('beforebegin', card.renderReadMore(id, anchorTag ? anchorTag.getAttribute('data-uuids').split(',').concat(uuids) : uuids)); } };