diff --git a/lib/farm.js b/lib/farm.js index 3c023d0..af8808d 100644 --- a/lib/farm.js +++ b/lib/farm.js @@ -116,12 +116,39 @@ const visitHarvestAll = async (state, page, url) => { state.preHarvestInventory = undefined } +const parseAnimalItems = (state, page) => { + let itemNames = [] + switch(state.lastView) { + case "coop": + itemNames = ["Eggs", "Feathers"] + break + case "pasture": + itemNames = ["Milk"] + break + case "raptors": + itemNames = ["Antlers", "Bobs"] + break + } + const animalItems = {} + const parser = new DOMParser() + const dom = parser.parseFromString(page, "text/html") + const items = dom.querySelectorAll(".card-content-inner > strong") + for (let i = 0; i < itemNames.length; i++) { + animalItems[itemNames[i]] = items[i].textContent + } + return animalItems +} + const visitCoop = async (state, page, url) => { state.lastView = "coop" + state.player.animalItems["Chickens"] = parseAnimalItems(state, page) + await state.player.save(state.db) } const visitPasture = async (state, page, url) => { state.lastView = "pasture" + state.player.animalItems["Cows"] = parseAnimalItems(state, page) + await state.player.save(state.db) } const visitPigPen = async (state, page, url) => { @@ -130,6 +157,8 @@ const visitPigPen = async (state, page, url) => { const visitPen = async (state, page, url) => { state.lastView = "raptors" + state.player.animalItems["Raptors"] = parseAnimalItems(state, page) + await state.player.save(state.db) } const visitHab = async (state, page, url) => { diff --git a/lib/player.js b/lib/player.js index 97d72db..5589a85 100644 --- a/lib/player.js +++ b/lib/player.js @@ -7,6 +7,7 @@ class Player { this.pets = {} this.cropImages = {} this.cropTimes = {} + this.animalItems = {} this.currentPerkset = null this.perksets = null this.settings = {}