Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add gender info in the moreInfo section #81

Closed
wants to merge 12 commits into from
Closed
Binary file added images/female.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gelding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/male.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
"48": "/images/icon-48x48.png",
"128": "/images/icon-128x128.png"
},
"web_accessible_resources": [
{
"resources": ["images/male.png", "images/female.png", "images/gelding.png"],
"matches": [
"*://*.equideow.com/*",
"*://*.howrse.com/*",
"*://*.howrse.no/*",
"*://*.howrse.co.uk/*",
"*://*.caballow.com/*"
]
}
],
"action": {
"default_popup": "popup.html"
},
Expand Down
31 changes: 28 additions & 3 deletions moreInfos.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

class MoreInfos {
constructor() {
this.parser = new DOMParser()
this.lang = translation.getLang(window.location.href)

this.regexpBlupHtml =
/<td class="last align-right" width="15%" dir="ltr"><strong class="nowrap">[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?<\/strong><\/td>/
this.regexpPGHtml =
Expand All @@ -19,12 +22,12 @@ class MoreInfos {
this.regexpPetHtmlSelf =
/<h3 id="compagnon-head-title" class="align-center module-style-6-title module-title">.*<\/h3>/

const genderLabel = `${translation.get(this.lang, 'sex', 'genderLabel')}`;
this.regexpSexHtml = `<td class="first"><strong>${genderLabel}<\/strong>\\s*(\\w+)<\/td>`;

this.regexpFloat = /[+-]?(?=\d*[.eE])(?=\.?\d)\d*\.?\d*(?:[eE][+-]?\d+)?/
this.regexpValue = /\>(.*?)\</

this.parser = new DOMParser()
this.lang = translation.getLang(window.location.href)

this.elevageLocation =
window.location.href.indexOf("elevage/chevaux/?elevage") > -1
this.sellsLocation = window.location.href.indexOf("marche/vente") > -1
Expand Down Expand Up @@ -84,6 +87,28 @@ class MoreInfos {
infoDiv.style.margin = ".25em 0"
infoDiv.style.color = "#993322"

if (this.elevageLocation) {
const imageContainerDiv = document.createElement("div")
imageContainerDiv.style.position = "absolute"
imageContainerDiv.style.top = "0"
imageContainerDiv.style.right = "0"

const sexHTML = data.match(this.regexpSexHtml);
const img = document.createElement("img")
if (sexHTML[1] === `${translation.get(this.lang, 'sex', 'female')}`) {
img.src = chrome.runtime.getURL("images/female.png")
} else if (sexHTML[1] === `${translation.get(this.lang, 'sex', 'male')}`) {
img.src = chrome.runtime.getURL("images/male.png")
} else {
img.src = chrome.runtime.getURL("images/gelding.png")
}
img.style.width = "auto"
img.style.height = "auto"
imageContainerDiv.appendChild(img)

infoDiv.appendChild(imageContainerDiv)
}

if (!this.boxesLocation && this.locationAllowed) {
const blupHtml = data.match(this.regexpBlupHtml)
const PetHtml =
Expand Down
30 changes: 30 additions & 0 deletions translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class Translation {
pet: 'Compagnon: ',
pg: 'PG: ',
skills: 'Compétences: '
},
sex: {
genderLabel: "Sexe:",
female: 'femelle',
male: 'mâle',
gelding: 'hongre'
}
},
en: {
Expand Down Expand Up @@ -55,6 +61,12 @@ class Translation {
pet: 'Pet: ',
pg: 'GP: ',
skills: 'Skills: '
},
sex: {
genderLabel: "Gender:",
female: 'female',
male: 'male',
gelding: 'gelding'
}
},
no: {
Expand Down Expand Up @@ -83,6 +95,12 @@ class Translation {
pet: 'Følgesvenner: ',
pg: 'GP: ',
skills: 'Ferdigheter: '
},
sex: {
genderLabel: "Gender:",
female: 'female',
male: 'male',
gelding: 'gelding'
}
},
pl: {
Expand Down Expand Up @@ -111,6 +129,12 @@ class Translation {
pet: 'Pet: ',
pg: 'GP: ',
skills: 'Skills: '
},
sex: {
genderLabel: "Gender:",
female: 'female',
male: 'male',
gelding: 'gelding'
}
},
es: {
Expand Down Expand Up @@ -139,6 +163,12 @@ class Translation {
pet: 'Mascota: ',
pg: 'PG: ',
skills: 'Habilidades: '
},
sex: {
genderLabel: "Sexo:",
female: 'hembra',
male: 'macho',
gelding: 'castrado'
}
}
}
Expand Down