diff --git a/README.md b/README.md index 143902f..8dd3b79 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Il s'agit la des nouvelles et anciennes version de l'extension trouvable en stor --- ## Better Howrse -Small chrome extension for Howrse that allow you to get more informations about your horses and competition difficulties. (highest coeff is highest winning rate) +Small browser extension for Howrse that allow you to get more informations about your horses and competition difficulties. (highest coeff is highest winning rate) Pet names displayed in the same way as other informations. Also will include theses infos from the research view @@ -22,7 +22,7 @@ Switch to the previous or next horse using left and right arrow keys on your key Here are available all recents and pasts updates of the browser extension that you can find on the stores. --- -[![Last Version](https://img.shields.io/badge/last%20version-v2.1.1-informational)](#) +[![Last Version](https://img.shields.io/badge/last%20version-v2.1.2-informational)](#) [![DeepScan grade](https://deepscan.io/api/teams/17688/projects/21040/branches/592899/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=17688&pid=21040&bid=592899) [![Chrome Web Store](https://img.shields.io/chrome-web-store/v/gkopbgamdhaolbjalfcbmbjkjcmgffjp)](https://chrome.google.com/webstore/detail/better-equideow/gkopbgamdhaolbjalfcbmbjkjcmgffjp) diff --git a/foodSelect.js b/foodSelect.js index 91912fc..11015df 100644 --- a/foodSelect.js +++ b/foodSelect.js @@ -8,51 +8,44 @@ class FoodSelect { constructor() { - this.feedingBtn = this.setHTMLElement("#boutonNourrir") - this.haySlider = this.setHTMLElement("#haySlider") || null // entire bloc containing ol, script, li, span - this.haySelectors = this.haySlider?.getElementsByTagName("span") // all span selectors from 0 to 20 - this.oatsSlider = this.setHTMLElement("#oatsSlider") || null + this.feedingBtn = document.getElementById("boutonNourrir") + this.haySlider = document.getElementById("haySlider") || null + this.haySelectors = this.haySlider?.getElementsByTagName("span") + this.oatsSlider = document.getElementById("oatsSlider") || null this.oatsSelectors = this.oatsSlider?.getElementsByTagName("span") } - setHTMLElement(element) { - return document.querySelector(element) - }; - getFoodIndex(foodNode) { - const foodValue = foodNode.innerHTML + const foodValue = foodNode.textContent const foodIndex = parseInt(foodValue) return foodIndex } - async run() { - // will get the value eg: XX/20 for hay and X/16 for oats. - const fourrageNode = document.getElementsByClassName( - "section-fourrage section-fourrage-target" - ) - const avoineNode = document.getElementsByClassName( - "section-avoine section-avoine-target" - ) + const fourrageNode = document.getElementsByClassName("section-fourrage section-fourrage-target")[0] + const avoineNode = document.getElementsByClassName("section-avoine section-avoine-target")[0] - if (fourrageNode.length > 0) { - const fourrageIndex = this.getFoodIndex(fourrageNode[0]) + if (fourrageNode) { + const fourrageIndex = this.getFoodIndex(fourrageNode) this.haySelectors[fourrageIndex].click() } - if (avoineNode.length > 0) { - const avoineIndex = this.getFoodIndex(avoineNode[0]) + if (avoineNode) { + const avoineIndex = this.getFoodIndex(avoineNode) this.oatsSelectors[avoineIndex].click() } } } -if (window.location.href.indexOf("elevage/chevaux/cheval?") > -1) { - const foodSelect = new FoodSelect() - if (foodSelect.feedingBtn !== null) +const horseFeedingPageRegex = /\/elevage\/chevaux\/cheval\?/ + +if (window.location.href.match(horseFeedingPageRegex)) { + let foodSelect = new FoodSelect() + if (foodSelect.feedingBtn !== null) { foodSelect.feedingBtn.addEventListener("click", () => { foodSelect.run() }) + } /** * @description generate a new FoodSelect() because after #loading style change, diff --git a/loadingDisplayObserver.js b/loadingDisplayObserver.js index f7a20eb..c57f7ee 100644 --- a/loadingDisplayObserver.js +++ b/loadingDisplayObserver.js @@ -11,6 +11,7 @@ class LoadingDisplayObserver { this.targetNode = document.querySelector('#loading'); this.config = { attributes: true, attributeFilter: ['style'] }; } + start() { return new Promise((resolve) => { this.observer = new MutationObserver((mutationsList) => { @@ -19,7 +20,8 @@ class LoadingDisplayObserver { let element = mutation.target; let display = window.getComputedStyle(element, null).getPropertyValue("display"); if (display === "none") { - resolve(); + resolve(); + this.stop(); } } } diff --git a/manifest.json b/manifest.json index 569e025..3b55caf 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "name": "__MSG_appName__", "description": "__MSG_appDesc__", "default_locale": "fr", - "version": "2.1.1", + "version": "2.1.2", "manifest_version": 3, "author": "TC-Dev", "icons": {