From 969009eed1e03f09245446a6fad331042b9ad8df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Sun, 28 Apr 2024 22:41:20 +0200 Subject: [PATCH] Change JS to not write to classList directly --- assets/script.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/assets/script.js b/assets/script.js index 21775ee..eb0a957 100644 --- a/assets/script.js +++ b/assets/script.js @@ -12,6 +12,17 @@ function isLoggedIn() { return UserInfo.Email && UserInfo.Email.length > 0; } +async function setElementClasses(element, newClasses) { + // Ensure the element exists + if (!element) return; + + // Clear all existing classes + element.className = ''; + + // Add the new classes to the element + element.classList.add(...newClasses); +} + async function handleResponse(data, successMessage, failureMessage) { "use strict"; const statusMessageContainer = document.getElementById("statusMessageContainer"); @@ -664,8 +675,8 @@ async function reloadMemeVotes(memeID) { memeVoteDownvoteButtonElement.classList.add('visual_hover'); } - memeVoteUpvoteElement.classList = [`ri-arrow-up-circle-${memeUpvoteVariant}`]; - memeVoteDownvoteElement.classList = [`ri-arrow-down-circle-${memeDownvoteVariant}`]; + await setElementClasses(memeVoteUpvoteElement, [`ri-arrow-up-circle-${memeUpvoteVariant}`]); + await setElementClasses(memeVoteDownvoteElement, [`ri-arrow-down-circle-${memeDownvoteVariant}`]) }