voting.js
ASCII text
1// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0 2 3function updateButtons(postID, score) { 4document.getElementById(postID + "-voteup").classList.remove("selected"); 5document.getElementById(postID + "-votedown").classList.remove("selected"); 6 7if(score == 1) { 8document.getElementById(postID + "-voteup").classList.add("selected"); 9} else if(score == -1) { 10document.getElementById(postID + "-votedown").classList.add("selected"); 11} 12} 13 14async function vote(postID, score) { 15if(score === 1) { 16action = "voteup"; 17} else if(score === -1) { 18action = "votedown"; 19} else { 20action = "votes"; 21} 22const response = await fetch(postID + "/" + action); 23const info = await response.text(); 24document.getElementById(postID + "-vote").innerText = info.split(" ")[0]; 25updateButtons(postID, info.split(" ")[1]) 26} 27 28// @license-end