Correction

This commit is contained in:
Dultus 2024-12-07 13:46:51 +01:00
parent f54eb75788
commit 5f60a928a2
4 changed files with 139 additions and 69 deletions

View file

@ -1,3 +1,4 @@
const url = 'http://127.0.0.1:5180/api/';
async function ping(){ async function ping(){
fetch ('http://127.0.0.1:5180/api/ping') fetch ('http://127.0.0.1:5180/api/ping')
.then(data => { .then(data => {
@ -10,44 +11,74 @@ async function setBaseDataHorseAPI(id, basedata) {
console.log("ID:", id); // Log ID to ensure it's received correctly console.log("ID:", id); // Log ID to ensure it's received correctly
console.log("Basedata:", basedata); // Log the entire horse data to check console.log("Basedata:", basedata); // Log the entire horse data to check
const url = `http://127.0.0.1:5180/api/setHorseBasicData/id=${id}`; const apiUrl = url+`setHorseBasicData/id=${id}`;
// Wait for the API call to complete // Wait for the API call to complete
const response = await fetch(url, { const response = await fetch(apiUrl, {
method: 'POST', method: 'POST',
body: JSON.stringify(basedata), body: JSON.stringify(basedata),
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}); });
console.log("API Response:", response); // Log the response from the API
const data = await response; // Wait for the response from the API
console.log("API Response:", data); // Log the response from the API
} catch (error) { } catch (error) {
console.error("Error setting horse data: " + error.message); console.error("Error setting horse data: " + error.message);
} }
} }
async function getHorseAPI(id) { async function getHorseAPI(id) {
var horseData; let horseData;
const url = 'http://127.0.0.1:5180/api/getHorseInfo/id=' + id; const apiUrl = url+`getHorseInfo/id=${id}`;
await fetch(url) await fetch(apiUrl)
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
horseData = data; horseData = data;
}); });
return horseData; return horseData;
} }
async function setHorsePedigreeAPI(id, pedigreeData) async function setHorsePedigreeAPIAsync(id, pedigreeData)
{ {
const url = `http://127.0.0.1:5180/api/setHorsePedigree/id=${id}`; const apiUrl = url+`setHorsePedigree/id=${id}`;
const response = await fetch(url, { const response = await fetch(apiUrl, {
method: 'POST', method: 'POST',
body: JSON.stringify(pedigreeData), body: JSON.stringify(pedigreeData),
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}); });
const data = await response; return response;
return data; }
async function setHorseTrainingAPIAsync(id, training)
{
const apiUrl = url+`setHorseTraining/id=${id}`;
const response = await fetch(apiUrl, {
method: 'POST',
body: JSON.stringify(training),
headers: {
'Content-Type': 'application/json'
}
});
}
async function setHorseGeneticsAPIAsync(id, genetics)
{
const apiUrl = url+`setHorseGenetics/id=${id}`;
const response = await fetch(apiUrl, {
method: 'POST',
body: JSON.stringify(genetics),
headers: {
'Content-Type': 'application/json'
}
});
}
async function setHorseHealthAPIAsync(id, health)
{
const apiUrl = url+`setHorseHealth/id=${id}`;
const response = await fetch(apiUrl, {
method: 'POST',
body: JSON.stringify(health),
headers: {
'Content-Type': 'application/json'
}
});
} }

View file

@ -1,4 +1,4 @@
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
if (request.action === "getHorseBasicData") { if (request.action === "getHorseBasicData") {
try { try {
console.log("Getting horse data"); console.log("Getting horse data");
@ -32,19 +32,19 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
else if (request.action === "getHorseCurrentData") else if (request.action === "getHorseCurrentData")
{ {
console.log("Getting current horse selected tab data"); console.log("Getting current horse selected tab data");
var selectedTab = getTabselText(); const selectedTab = getTabselText();
console.log("Selected tab:", selectedTab); console.log("Selected tab:", selectedTab);
if (selectedTab === "Summary") if (selectedTab === "Summary")
{ {
var relatedHorses = Array.from(document.querySelectorAll('.pedigree a')).map(link => link.href); let relatedHorses = Array.from(document.querySelectorAll('.pedigree a')).map(link => link.href);
var response = setHorsePedigreeAPI(request.data.id, relatedHorses); let response = await setHorsePedigreeAPIAsync(request.data.id, relatedHorses);
console.log("Response from API:", response); console.log("Response from API:", response);
sendResponse({ success: true, data: response }); sendResponse({ success: true, data: response });
} }
else if (selectedTab === "Training") else if (selectedTab === "Training")
{ {
var training = document.querySelector('.top:nth-child(8)') ? document.querySelector('.top:nth-child(8)').innerText : document.querySelector('.top:nth-child(6)').innerText; let training = document.querySelector('.top:nth-child(8)') ? document.querySelector('.top:nth-child(8)').innerText : document.querySelector('.top:nth-child(6)').innerText;
var response = setHorseTrainingAPI(request.data.id, training); let response = await setHorseTrainingAPIAsync(request.data.id, training);
console.log("Response from API:", response); console.log("Response from API:", response);
sendResponse({ success: true, data: response }); sendResponse({ success: true, data: response });
} }
@ -57,20 +57,23 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
.map(value => parseFloat(value)); .map(value => parseFloat(value));
const totalGeneticPotential = (Array.from(document.querySelectorAll('.top div')).find(el => el.innerText.includes('GP'))?.innerText || "").replace("GP total: ", "").trim(); const totalGeneticPotential = (Array.from(document.querySelectorAll('.top div')).find(el => el.innerText.includes('GP'))?.innerText || "").replace("GP total: ", "").trim();
var response = setHorseGeneticsAPI(request.data.id, colorGenetics); let response = setHorseGeneticsAPI(request.data.id, colorGenetics);
console.log("Response from API:", response); console.log("Response from API:", response);
sendResponse({ success: true, data: response }); sendResponse({ success: true, data: response });
} }
else if (selectedTab === "Achievements") else if (selectedTab === "Achievements")
{ {
var genetics = Array.from(document.querySelectorAll('.genetic_stats')).map(x => x.innerText).filter(text => /poor|below average|average|good|very good/i.test(text)); let genetics = Array.from(document.querySelectorAll('.genetic_stats')).map(x => x.innerText).filter(text => /poor|below average|average|good|very good/i.test(text)); // Walk, Trot, Canter, Gallop, Posture...
var response = setHorseGeneticsAPI(request.data.id, genetics); let response = setHorseAchievementsAPI(request.data.id, genetics);
// Second part of the achievements tab needed for show results
// Placeholder
let response2 = setHorseConformationAPI(request.data.id, { });
console.log("Response from API:", response); console.log("Response from API:", response);
} }
else if (selectedTab === "Health") else if (selectedTab === "Health")
{ {
var health = [...document.querySelector("#tab_health2 p").innerText.matchAll(/:\s*(\w+)/g)].map(match => match[1]); let health = [...document.querySelector("#tab_health2 p").innerText.matchAll(/:\s*(\w+)/g)].map(match => match[1]);
var response = setHorseHealthAPI(request.data.id, health); let response = setHorseHealthAPI(request.data.id, health);
console.log("Response from API:", response); console.log("Response from API:", response);
} }
else else
@ -81,9 +84,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
return true; // This is necessary to allow asynchronous response return true; // This is necessary to allow asynchronous response
}); });
function getTabselText() { function getTabselText() {
const tabElement = document.querySelector('div.tabsel'); const tabElement = document.querySelector('div.tabsel').textContent?.trim();
if (tabElement) { return tabElement;
return tabElement.textContent.trim();
}
return null;
} }

View file

@ -1,4 +1,5 @@
// Modell für ein Pferd // Modell für ein Pferd
var globalHorse = { var globalHorse = {
// Basic // Basic
id: null, // ID of the horse id: null, // ID of the horse
@ -13,27 +14,27 @@ var globalHorse = {
// Training // Training
training: null, // training of the horse e.g. Basic Training training: null, // training of the horse e.g. Basic Training
// Genetics // Genetics
GP: 0, // GP of the horse gp: 0, // GP of the horse
features: {}, // features of the horse e.g. Dressage, Driving, Endurance etc. features: {}, // features of the horse e.g. Dressage, Driving, Endurance etc.
// Genes // Genes
Extension: null, // Extension gene of the horse extension: null, // Extension gene of the horse
Agouti: null, // Agouti gene of the horse agouti: null, // Agouti gene of the horse
Grey: null, // Grey gene of the horse grey: null, // Grey gene of the horse
Cream: null, // Cream gene of the horse cream: null, // Cream gene of the horse
Dun: null, // Dun gene of the horse dun: null, // Dun gene of the horse
Champagne: null, // Champagne gene of the horse champagne: null, // Champagne gene of the horse
Silver: null, // Silver gene of the horse silver: null, // Silver gene of the horse
Mushroom: null, // Mushroom gene of the horse mushroom: null, // Mushroom gene of the horse
Frame: null, // Frame gene of the horse frame: null, // Frame gene of the horse
Appaloosa: null, // Appaloosa gene of the horse appaloosa: null, // Appaloosa gene of the horse
PATN1: null, // PATN1 gene of the horse patn1: null, // PATN1 gene of the horse
MITF: null, // MITF gene of the horse mitf: null, // MITF gene of the horse
SW2: null, // SW2 gene of the horse sw2: null, // SW2 gene of the horse
KIT: null, // KIT gene of the horse kit: null, // KIT gene of the horse
RAB: null, // RAB gene of the horse rab: null, // RAB gene of the horse
Seal: null, // Seal gene of the horse seal: null, // Seal gene of the horse
Flaxen: null, // Flaxen gene of the horse flaxen: null, // Flaxen gene of the horse
// Achievements // Achievements
conformation: {}, // conformation of the horse e.g. Walk, Trot, Canter, Gallop, Jumping, Dressage conformation: {}, // conformation of the horse e.g. Walk, Trot, Canter, Gallop, Jumping, Dressage

View file

@ -92,30 +92,68 @@ document.addEventListener("DOMContentLoaded", function () {
rowDiv.appendChild(emojiCell); rowDiv.appendChild(emojiCell);
table.appendChild(rowDiv); table.appendChild(rowDiv);
}); });
const infoTextLoaded = document.createElement('p');
infoTextLoaded.textContent = '✅ Loaded'; // Linie hinzufügen
infoTextLoaded.justifyContent = 'space-between'; const line = document.createElement('hr');
infoTextLoaded.width = '100%'; Object.assign(line.style, {
const infoTextDynamic = document.createElement('p'); width: '100%',
infoTextDynamic.textContent = '☑️ Dynamic'; border: '0',
infoTextDynamic.justifyContent = 'space-between'; height: '1px',
infoTextDynamic.width = '100%'; backgroundColor: '#ddd',
const infoTextNeedRefresh = document.createElement('p'); margin: '10px 0'
infoTextNeedRefresh.textContent = '🔄 Needs Refresh'; });
infoTextNeedRefresh.justifyContent = 'space-between';
infoTextNeedRefresh.width = '100%'; // Legend-Titel hinzufügen
const infoTextNotLoaded = document.createElement('p'); const legendTitle = document.createElement('div');
infoTextNotLoaded.textContent = '❌ Not Loaded'; legendTitle.textContent = 'Legend:';
infoTextNotLoaded.justifyContent = 'space-between'; Object.assign(legendTitle.style, {
infoTextNotLoaded.width = '100%'; fontWeight: 'bold',
fontSize: '14px',
// Button oben hinzufügen, dann die Tabelle color: '#555'
});
// Info-Text für die Legende hinzufügen
const legendTexts = [
{ emoji: '✅', text: 'Loaded' },
{ emoji: '☑️', text: 'Dynamic' },
{ emoji: '🔄', text: 'Needs Refresh' },
{ emoji: '❌', text: 'Not Loaded' },
];
const legend = document.createElement('div');
Object.assign(legend.style, {
display: 'flex',
flexDirection: 'column',
gap: '5px',
fontSize: '12px',
color: '#333'
});
legendTexts.forEach(item => {
const legendRow = document.createElement('div');
Object.assign(legendRow.style, {
display: 'flex',
alignItems: 'center',
gap: '5px'
});
const emoji = document.createElement('span');
emoji.textContent = item.emoji;
emoji.style.fontSize = '14px';
const text = document.createElement('span');
text.textContent = item.text;
legendRow.appendChild(emoji);
legendRow.appendChild(text);
legend.appendChild(legendRow);
});
// Button oben hinzufügen, dann die Tabelle, Linie, und die Legende
div.appendChild(updateHorseButton); div.appendChild(updateHorseButton);
div.appendChild(table); div.appendChild(table);
div.appendChild(infoTextLoaded); div.appendChild(line);
div.appendChild(infoTextDynamic); div.appendChild(legendTitle);
div.appendChild(infoTextNotLoaded); div.appendChild(legend);
div.appendChild(infoTextNeedRefresh);
banner.appendChild(div); banner.appendChild(div);
} }
}); });