Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Tool for votecounts - can be used for current or retrospective votecounts
- * To use, load posts from start of day up until desired post (or thread end for current VCs),
- * and fill in the correct information below
- * For d2+, just load from SOD, not start of game
- * Votes are case-sensitive; bold and code are both counted, Vote: Unvote and Unvote are both counted
- */
- // For each player in the game, insert into playerlist a string "<name>", without the comma for the last one.
- // Playerlist must be start of game
- var playerlist = ["Aminecraftbear", "ChrisalonaLiverspur", "Cosmosiq", "DXtreme", "Mathletesv", "NDMath", "WisteriaV", "ad333", "adrastea", "falliinqsnow-", "galaxy1220", "itsjustWanderlust", "jkittykitkat", "lovematch13", "lucaswujc", "mark888", "mathjay", "ostriches88", "saturnrocket", "scannose", "vietaformula810"];
- var start = 6; // SOD postnum
- //var start = prompt("What post did day start?"); // can use this instead if you want
- /* Replacements must be in order
- * Each replacement: [postnum, player who replaced out, player who replaced in]
- * Sample:
- * var replacements = [
- * [123, "player1", "player2"],
- * [1610, "player3", "player4"],
- * ];
- * (Comma at end of each replacement except the last) */
- var replacements = [
- [5, "lovematch13", "dragonlouis"],
- [1202, "ostriches88", "Madelyn"],
- [1637, "galaxy1220", "hellomynameisjoe"],
- [2581, "dragonlouis", "lovematch13"],
- [2982, "adrastea", "G3don"],
- [3134, "lucaswujc", "sheepsaysmeep"],
- [3537, "G3don", "violetmx12"],
- [3963, "falliinqsnow-", "Scipio1"]
- ];
- /* Fill in all deaths in order by post, similar to replacements
- * Sample, with two deaths in post 1236:
- * var deaths = [
- * [1234, "player1", "Town"],
- * [1236, "player2", "Mafia"],
- * [1236, "player3", "Town"]
- * ];
- * Alignment should be Town or Mafia, anything else is no alignment
- */
- var deaths = [
- [2575, "DXtreme", "Town"],
- [2582, "Aminecraftbear", "Town"],
- [3532, "lovematch13", "Town"],
- [3532, "itsjustWanderlust", "Town"],
- [3541, "WisteriaV", "Town"]
- ];
- // If you want some text at the bottom of the votecount
- var lastline = "";
- var color = "[color=#00f]"; // Custom color; only for current votecounts
- var majOn = false; // If enabled, L-2 and L-1 will show in the votecount (untested)
- /*********/
- /* Below options are only for a retrospective votecount */
- /* For a retrospective votecount, comment out the below line and uncomment the line after, or set postNum directly
- A postNum of zero means a current votecount, not a retrospective one */
- //var postNum = 0; // post that you want a votecount for
- var postNum = prompt("What post do you want a votecount for?");
- var day = 1; // Set to correct day if using retrospective votecount
- /*********/
- //Turn off AoPS Enhanced if you have it before using
- $("div.bbcode_quote").remove();
- $("span.cmty-hide-heading faux-link").remove();
- $("div.cmty-hide-content").remove();
- // End of info for user
- /***********************************/
- function hasVoteStr(voteStr, post) {
- // Check whether a post contains a certain vote
- if ($(".cmty-post-html")[post].innerHTML.includes("<b>" + voteStr)
- || $(".cmty-post-html")[post].innerHTML.includes("<pre class=\"c\" style=\"font-family:monospace;background-color: #f4f6f4;padding:10px;\">" + voteStr)
- || $(".cmty-post-html")[post].innerHTML.includes("<code>" + voteStr)) {
- return true;
- } else if (voteStr.slice(0, 6) === "Vote: " && $(".cmty-post-html")[post].innerHTML.includes("<pre class=\"c\" style=\"font-family:monospace;background-color: #f4f6f4;padding:10px;\">Vote<span style=\"color: #339933;\">:</span> " + voteStr.slice(6))) {
- // Handle edge case with code tags - colon in "Vote: " is a different color
- return true;
- } else {
- return false;
- }
- }
- function processVote(poster, target, a) {
- var oldVote = players[poster]["vote"];
- if (oldVote != target) {
- // Not already voting that player -> change vote
- if (oldVote != "None") {
- players[oldVote]["numVotes"]--;
- players[oldVote]["voters"].splice(players[oldVote]["voters"].indexOf(poster), 1);
- if (players[oldVote]["voters"].length > 0) {
- players[oldVote]["wagonTailPost"] = players[players[oldVote]["voters"][players[oldVote]["voters"].length - 1]]["votePost"];
- }
- } else {
- notVoting.splice(notVoting.indexOf(poster), 1);
- }
- players[target]["numVotes"] += 1;
- players[target]["voters"].push(poster);
- players[poster]["vote"] = target;
- }
- $(".cmty-post-number")[a].click();
- players[target]["wagonTailPost"] = Number($(".cmty-post-number")[a].innerHTML.slice(1));
- players[poster]["votePost"] = players[target]["wagonTailPost"];
- players[poster]["voteURL"] = " ([url=" + $(".cmty-post-direct-modal > input")[0].value + "]" + $(".cmty-post-number")[a].innerHTML + "[/url])";
- $("a.aops-close-x").click();
- }
- function voteCompare(a, b) {
- // Sort wagons in descending order
- if (players[a]["numVotes"] == players[b]["numVotes"]) {
- // Ties broken by postnum of last vote on player
- return players[a]["wagonTailPost"] - players[b]["wagonTailPost"];
- } else {
- return players[b]["numVotes"] - players[a]["numVotes"];
- }
- }
- /* Enables loading only from SOD on D2+ rather than loading entire thread
- - The index of a post is based on the number of posts loaded rather than post numbers,
- so map postnum to index out of loaded posts */
- var adjusted_start = $(".cmty-post-number").index($(".cmty-post-number").filter(":contains(" + start.toString() + ")"));
- //var adjusted_start = $(".cmty-post-number").index(":contains(" + start.toString() + ")"); // this would be more efficient, but it doesn't work. not sure why
- var adjusted_end;
- if (postNum > 0) {
- adjusted_end = $(".cmty-post-number").index($(".cmty-post-number").filter(":contains(" + postNum.toString() + ")"));
- } else {
- adjusted_end = $(".cmty-post").length - 1; // Current VC
- }
- var replaceInd = 0;
- var replacePost = 0;
- if (replacements.length !== 0) {
- replacePost = replacements[replaceInd][0];
- }
- while (replaceInd < replacements.length && replacePost <= start) {
- for (let d of deaths) {
- if (d[1] == replacements[replaceInd][1]) {
- d[1] = replacements[replaceInd][2];
- }
- }
- let plInd = playerlist.indexOf(replacements[replaceInd][1]);
- if (plInd < 0) {
- console.log("Warning: " + replacements[replaceInd][1] + " in replacements but not in playerlist, skipping");
- } else {
- playerlist[plInd] = replacements[replaceInd][2];
- console.log("Processed replacement from earlier in post " + replacePost + ": " + replacements[replaceInd][2] + " for " + replacements[replaceInd][1]);
- }
- replaceInd++;
- if (replaceInd < replacements.length) {
- replacePost = replacements[replaceInd][0];
- } else {
- // If there's no replacements left, adjust to a post we'll never hit
- replacePost = adjusted_end + start - adjusted_start + 1;
- }
- }
- var deathInd = 0;
- var deathPost = 0;
- if (deaths.length !== 0) {
- deathPost = deaths[deathInd][0];
- }
- while (deathInd < deaths.length && deathPost <= start) {
- let plInd = playerlist.indexOf(deaths[deathInd][1]);
- if (plInd < 0) {
- console.log("Warning: " + deaths[deathInd][1] + " in deaths but not in playerlist, skipping");
- } else {
- playerlist.splice(plInd, 1);
- console.log("Processed death from earlier in post " + deathPost + ": " + deaths[deathInd][1]);
- }
- deathInd++;
- if (deathInd < deaths.length) {
- deathPost = deaths[deathInd][0];
- } else {
- // If there's no deaths left, adjust to a post we'll never hit
- deathPost = adjusted_end + start - adjusted_start + 1;
- }
- }
- var players = {};
- var notVoting = [];
- playerlist.push("No Hang");
- for (let player of playerlist) {
- players[player] = {};
- players[player]["numVotes"] = 0;
- players[player]["voters"] = [];
- players[player]["vote"] = "None";
- players[player]["voteURL"] = "";
- players[player]["wagonTailPost"] = 0;
- players[player]["votePost"] = 0;
- players[player]["alignment"] = "None";
- players[player]["postcount"] = 0;
- if (player != "No Hang") {
- notVoting.push(player);
- }
- // Below is old stuff, keeping it around for reference
- //players[player] = [0, [], "None", "", 0, 0, "None"];
- /* Indices of players[player]:
- 0: Number of votes
- 1: Players voting them
- 2: who they're voting
- 3: URL of last vote
- 4: postnum of last vote on them
- 5: postnum of their last vote
- 6: flipped alignment
- */
- }
- var voter;
- for (let a = adjusted_start; a <= adjusted_end; a++) {
- // Process replacement
- while (a + start - adjusted_start === replacePost) {
- let subOut = replacements[replaceInd][1];
- let subIn = replacements[replaceInd][2];
- let voteTarget = players[subOut]["vote"];
- if (!(subOut in players)) {
- console.log("post " + replacePost + ": " + subOut + " not currently in game, not processing replacment");
- } else {
- // Adjust for player who is voted by replacement
- if (voteTarget !== "None") {
- players[voteTarget]["voters"][players[voteTarget]["voters"].indexOf(subOut)] = subIn;
- }
- // Adjust for players voting replacement
- for (let repVoter of players[subOut]["voters"]) {
- players[repVoter]["vote"] = subIn;
- }
- // Adjust players, notVoting, playerlist
- playerlist[playerlist.indexOf(subOut)] = subIn;
- players[subIn] = players[subOut];
- delete players[subOut];
- let nvInd = notVoting.indexOf(subOut);
- if (nvInd >= 0) {
- notVoting[nvInd] = subIn;
- }
- for (let d of deaths) {
- if (d[1] == replacements[replaceInd][1]) {
- d[1] = replacements[replaceInd][2];
- }
- }
- console.log("Processed replacement in post " + (a + start - adjusted_start) + ": " + subIn + " for " + subOut);
- }
- replaceInd++;
- if (replaceInd < replacements.length) {
- replacePost = replacements[replaceInd][0];
- } else {
- // If there's no replacements left, adjust to a post we'll never hit
- replacePost = adjusted_end + start - adjusted_start + 1;
- }
- }
- // Process deaths during the day
- while (a + start - adjusted_start === deathPost) {
- let dead = deaths[deathInd][1];
- let voteTarget = players[dead]["vote"];
- if (!(dead in players)) {
- console.log("post " + replacePost + ": " + subOut + " not currently in game, not processing replacment");
- } else {
- if (voteTarget !== "None") {
- players[voteTarget]["voters"].splice(players[voteTarget]["voters"].indexOf(dead), 1);
- }
- // Adjust for players voting dead player
- for (let deadVoter of players[dead]["voters"]) {
- players[deadVoter]["vote"] = "None";
- notVoting.push(voter);
- }
- // Adjust players, notVoting, playerlist
- playerlist.splice(playerlist.indexOf(dead), 1);
- delete players[dead];
- let nvInd = notVoting.indexOf(dead);
- if (nvInd >= 0) {
- notVoting.splice(nvInd, 1);
- }
- console.log("Processed death in post " + (a + start - adjusted_start) + ": " + dead);
- }
- deathInd++;
- if (deathInd < deaths.length) {
- deathPost = deaths[deathInd][0];
- } else {
- // If there's no deaths left, adjust to a post we'll never hit
- deathPost = adjusted_end + start - adjusted_start + 1;
- }
- }
- voter = $(".cmty-post-username > a")[a].innerHTML;
- if (voter in players) {
- players[voter]["postcount"]++;
- if ((hasVoteStr("Unvote", a) || hasVoteStr("Vote: Unvote", a)) && players[voter]["vote"] != "None") {
- // Process unvote
- let oldVote = players[voter]["vote"];
- players[oldVote]["numVotes"]--;
- players[oldVote]["voters"].splice(players[oldVote]["voters"].indexOf(voter), 1);
- if (players[oldVote]["voters"].length > 0) {
- // Update last vote on wagon, if the wagon still exists
- players[oldVote]["wagonTailPost"] = players[players[oldVote]["voters"].slice(-1)]["votePost"];
- }
- notVoting.push(voter);
- players[voter]["vote"] = "None";
- $(".cmty-post-number")[a].click();
- players[voter]["voteURL"] = " ([url=" + $(".cmty-post-direct-modal > input")[0].value + "]" + $(".cmty-post-number")[a].innerHTML + "[/url])";
- players[voter]["votePost"] = Number($(".cmty-post-number")[a].innerHTML.slice(1));
- $("a.aops-close-x").click();
- }
- if (hasVoteStr("Vote: ", a)) {
- for (var voted in players) {
- if (hasVoteStr("Vote: " + voted, a)) {
- processVote(voter, voted, a);
- }
- }
- }
- }
- }
- while (deathInd < deaths.length) {
- // Set alignments of players who die later for retro VC
- let dead = deaths[deathInd][1];
- if (!(dead in players)) {
- console.log("Warning: " + dead + " in deaths but not in playerlist, skipping");
- } else {
- players[dead]["alignment"] = deaths[deathInd][2];
- }
- deathInd++;
- }
- var notText = "[b]Not Voting (" + notVoting.length + "):[/b] ";
- for (let a = 0; a < notVoting.length; a++) {
- if (a !== 0) {
- notText += ", ";
- }
- voter = notVoting[a];
- if (players[voter]["alignment"] == "Town") {
- notText += "[color=#38761D]";
- notText += voter;
- notText += "[/color]";
- notText += players[voter]["voteURL"];
- } else if (players[voter]["alignment"] == "Mafia") {
- notText += "[color=#f00]";
- notText += voter;
- notText += "[/color]";
- notText += players[voter]["voteURL"];
- } else {
- notText += voter + players[voter]["voteURL"];
- }
- }
- var voteCounters = []
- for (let player of playerlist) {
- voteCounters.push(player);
- }
- voteCounters.sort(voteCompare);
- var voteText = "";
- for (let i = 0; i < voteCounters.length; i++) {
- if (players[voteCounters[i]]["numVotes"] == 0) {
- break;
- }
- voteText += "[b]" + voteCounters[i] + " (" + players[voteCounters[i]]["numVotes"].toString();
- if (majOn) {
- // note players.length includes No Hang
- if (voteCounters[i] != "No Hang" && players[voteCounters[i]]["numVotes"] == Math.ceil((players.length) / 2 - 2)
- || voteCounters[i] == "No Hang" && players[voteCounters[i]]["numVotes"] == Math.floor((players.length) / 2 - 2)) {
- voteText += ", L-2";
- } else if (voteCounters[i] != "No Hang" && players[voteCounters[i]]["numVotes"] == Math.ceil((players.length) / 2 - 1)
- || voteCounters[i] == "No Hang" && players[voteCounters[i]]["numVotes"] == Math.floor((players.length) / 2 - 1)) {
- voteText += ", L-1";
- }
- }
- voteText += "):[/b] ";
- for (let j = 0; j < players[voteCounters[i]]["voters"].length; j++) {
- voter = players[voteCounters[i]]["voters"][j];
- if (players[voter]["alignment"] == "Town") {
- voteText += "[color=#38761D]";
- voteText += voter;
- voteText += "[/color]";
- voteText += players[voter]["voteURL"];
- } else if (players[voter]["alignment"] == "Mafia") {
- voteText += "[color=#f00]";
- voteText += voter;
- voteText += "[/color]";
- voteText += players[voter]["voteURL"];
- } else {
- voteText += voter + players[voter]["voteURL"];
- }
- if (j === players[voteCounters[i]]["voters"].length - 1) {
- voteText += "\n";
- } else {
- voteText += ", ";
- }
- }
- }
- voteCounters.sort((a, b) => players[b]["postcount"] - players[a]["postcount"]);
- var postcounts = "[hide=Postcounts]";
- for (let player of voteCounters) {
- if (player != "No Hang") {
- postcounts += player + ": " + players[player]["postcount"] + "\n";
- }
- }
- postcounts += "[/hide]";
- var post = "";
- if (postNum <= 0) {
- // Current VC
- post = color + "[b][u]Automatic Votecount " + prompt("What votecount is it?") + "[/u][/b]\n" + voteText + "\n" + notText;
- } else {
- // Retro VC
- post = "[b][u]Votecount for Post " + postNum + " (Day " + day + ")[/u][/b]\n" + voteText + "\n" + notText;
- }
- post += "\n" + postcounts;
- if (lastline.length > 0) {
- post += "\n\n" + lastline;
- }
- $(".cmty-topic-mini-reply").click();
- $(".cmty-post-textarea").val(post);
- console.log("Votecount added to reply box");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement