By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

 voting.js

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