Lampa-Plugins/vote-color.js

24 lines
918 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function updateVoteColors() {
document.querySelectorAll(".card__vote").forEach(voteElement => {
const vote = parseFloat(voteElement.textContent.trim());
if (vote >= 0 && vote <= 3) {
voteElement.style.color = "red";
} else if (vote >= 3 && vote <= 5.9) {
voteElement.style.color = "orange";
} else if (vote >= 6 && vote <= 7.9) {
voteElement.style.color = "cornflowerblue";
} else if (vote >= 8 && vote <= 10) {
voteElement.style.color = "lawngreen";
}
});
}
document.addEventListener("DOMContentLoaded", function () {
setTimeout(updateVoteColors, 500);
});
// Следим за изменениями в контейнере с карточками
const observer = new MutationObserver(updateVoteColors);
observer.observe(document.body, { childList: true, subtree: true });