Last active
June 12, 2020 17:46
-
-
Save umr55766/1628de4c5968f884cc4053edffc271a8 to your computer and use it in GitHub Desktop.
Colonist : Javascript code to calculate approximate number of cards user have
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
userData = { | |
"Kapoor#1292": { | |
"brick": 0, | |
"grain": 0, | |
"lumber": 0, | |
"ore": 0, | |
"wool": 0 | |
}, | |
"Nadeem#5285": { | |
"brick": 0, | |
"grain": 0, | |
"lumber": 0, | |
"ore": 0, | |
"wool": 0 | |
}, | |
"SPD#1889": { | |
"brick": 0, | |
"grain": 0, | |
"lumber": 0, | |
"ore": 0, | |
"wool": 0 | |
}, | |
"Sasank#0768": { | |
"brick": 0, | |
"grain": 0, | |
"lumber": 0, | |
"ore": 0, | |
"wool": 0 | |
}, | |
"Sudha": { | |
"brick": 0, | |
"grain": 0, | |
"lumber": 0, | |
"ore": 0, | |
"wool": 0 | |
}, | |
"Umair": { | |
"brick": 0, | |
"grain": 0, | |
"lumber": 0, | |
"ore": 0, | |
"wool": 0 | |
}, | |
"nithya": { | |
"brick": 0, | |
"grain": 0, | |
"lumber": 0, | |
"ore": 0, | |
"wool": 0 | |
}, | |
"nithys#7191": { | |
"brick": 0, | |
"grain": 0, | |
"lumber": 0, | |
"ore": 0, | |
"wool": 0 | |
}, | |
}; | |
var images, cards, building, userId; | |
Array.from(document.querySelector("#game-log-text").children).forEach(el => { | |
if (el.textContent.indexOf("got") >= 0) { | |
userId = el.textContent.split(" ")[0]; | |
images = Array.from(el.getElementsByTagName("img")); | |
cards = []; | |
for (var i = 1; i < images.length; i++) { | |
src = images[i].getAttribute("src").substring(20); | |
cards.push(src.substring(0, src.length - 8)); | |
} | |
cards.forEach(card => userData[userId][card] += 1) | |
} else if (el.textContent.indexOf("built") >= 0) { | |
userId = el.textContent.split(" ")[0]; | |
src = el.getElementsByTagName("img")[1].getAttribute("src").substring(15); | |
src = src.substring(0, src.length-8); | |
building = src.split("_")[0]; | |
if(building == "road") { | |
userData[userId]["brick"] -= 1; | |
userData[userId]["lumber"] -= 1; | |
} | |
else if(building == "city") { | |
userData[userId]["ore"] -= 3; | |
userData[userId]["grain"] -= 2; | |
} | |
else if(building == "settlement") { | |
userData[userId]["wool"] -= 1; | |
userData[userId]["lumber"] -= 1; | |
userData[userId]["brick"] -= 1; | |
userData[userId]["grain"] -= 1; | |
} | |
} else if (el.textContent.indexOf("stole") >= 0) { | |
userId = el.textContent.split(" ")[0]; | |
// stole | |
} else if (el.textContent.indexOf("bought") >= 0) { | |
userId = el.textContent.split(" ")[0]; | |
// Bought development card | |
} else if (el.textContent.indexOf("gave bank") >= 0) { | |
userId = el.textContent.split(" ")[0]; | |
// traded with bank | |
} else if (el.textContent.indexOf("traded with") >= 0) { | |
userId = el.textContent.split(" ")[0]; | |
// traded with another player | |
} else if (el.textContent.indexOf("Needs to discard") >= 0) { | |
userId = el.textContent.split(" ")[0]; | |
// discarded | |
} | |
}) | |
console.table(userData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment