/* This is a small script to hide the "up" arrow when users upvote * posts and comments. The only reason for this is to give some feedback * to the user after clicks. */ function vote (action, dom_element) { var arrow_up = dom_element.children[0]; var vote_counter = dom_element.children[1]; var arrow_down = dom_element.children[2]; // Voted/Upvoted var current_status = 0; if ("upvoted" == arrow_up.className) current_status = 1; if ("downvoted" == arrow_down.className) current_status = -1; // Current vote var current_vote = Number (vote_counter.textContent); // Remove class from arrows arrow_up.className = ""; arrow_down.className = ""; // Toggle upvote class for arrow if ("up" == action) switch (current_status) { case -1: vote_counter.textContent = current_vote + 2; arrow_up.className = "upvoted"; break; case 0: vote_counter.textContent = current_vote + 1; arrow_up.className = "upvoted"; break; case 1: vote_counter.textContent = current_vote - 1; break; } // Toggle downvote class for arrow if ("down" == action) switch (current_status) { case -1: vote_counter.textContent = current_vote + 1; break; case 0: vote_counter.textContent = current_vote - 1; arrow_down.className = "downvoted"; break; case 1: vote_counter.textContent = current_vote - 2; arrow_down.className = "downvoted"; break; } }