voting.js
ASCII text
1function updateButtons(postID, score) { 2document.getElementById(postID + "-voteup").classList.add("button-flat"); 3document.getElementById(postID + "-votedown").classList.add("button-flat"); 4 5if(score == 1) { 6document.getElementById(postID + "-voteup").classList.remove("button-flat"); 7} else if(score == -1) { 8document.getElementById(postID + "-votedown").classList.remove("button-flat"); 9} 10} 11 12async function vote(postID, score) { 13if(score === 1) { 14action = "voteup"; 15} else if(score === -1) { 16action = "votedown"; 17} else { 18action = "votes"; 19} 20const response = await fetch(postID + "/" + action); 21const info = await response.text(); 22document.getElementById(postID + "-vote").innerText = info.split(" ")[0]; 23updateButtons(postID, info.split(" ")[1]) 24} 25