Lampa-Plugins/ratingColor.js

21 lines
779 B
JavaScript

function updateRating(){
let cardVote = document.querySelectorAll('.card__vote');
for(let voteCard of cardVote){
if (voteCard.innerHTML >= 0 && voteCard.innerHTML <= 3.9) {
voteCard.style.color = "red";
} else if (voteCard.innerHTML >= 4 && voteCard.innerHTML <= 6.9) {
voteCard.style.color = "orange";
} else if (voteCard.innerHTML >= 7 && voteCard.innerHTML <= 7.9) {
voteCard.style.color = "lightgreen";
} else if (voteCard.innerHTML >= 8 && voteCard.innerHTML <= 10) {
voteCard.style.color = "lawngreen";
}
}
}
document.addEventListener("DOMContentLoaded", function () {
setTimeout(updateRating, 500);
});
const observer = new MutationObserver(updateRating);
observer.observe(document.body, { childList: true, subtree: true });