Correction
This commit is contained in:
parent
f54eb75788
commit
5f60a928a2
4 changed files with 139 additions and 69 deletions
|
|
@ -1,3 +1,4 @@
|
|||
const url = 'http://127.0.0.1:5180/api/';
|
||||
async function ping(){
|
||||
fetch ('http://127.0.0.1:5180/api/ping')
|
||||
.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("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
|
||||
const response = await fetch(url, {
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(basedata),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
const data = await response; // Wait for the response from the API
|
||||
console.log("API Response:", data); // Log the response from the API
|
||||
console.log("API Response:", response); // Log the response from the API
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error setting horse data: " + error.message);
|
||||
}
|
||||
}
|
||||
async function getHorseAPI(id) {
|
||||
var horseData;
|
||||
const url = 'http://127.0.0.1:5180/api/getHorseInfo/id=' + id;
|
||||
await fetch(url)
|
||||
let horseData;
|
||||
const apiUrl = url+`getHorseInfo/id=${id}`;
|
||||
await fetch(apiUrl)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
horseData = data;
|
||||
});
|
||||
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 response = await fetch(url, {
|
||||
const apiUrl = url+`setHorsePedigree/id=${id}`;
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(pedigreeData),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
const data = await response;
|
||||
return data;
|
||||
return response;
|
||||
}
|
||||
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'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => {
|
||||
if (request.action === "getHorseBasicData") {
|
||||
try {
|
||||
console.log("Getting horse data");
|
||||
|
|
@ -32,19 +32,19 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||
else if (request.action === "getHorseCurrentData")
|
||||
{
|
||||
console.log("Getting current horse selected tab data");
|
||||
var selectedTab = getTabselText();
|
||||
const selectedTab = getTabselText();
|
||||
console.log("Selected tab:", selectedTab);
|
||||
if (selectedTab === "Summary")
|
||||
{
|
||||
var relatedHorses = Array.from(document.querySelectorAll('.pedigree a')).map(link => link.href);
|
||||
var response = setHorsePedigreeAPI(request.data.id, relatedHorses);
|
||||
let relatedHorses = Array.from(document.querySelectorAll('.pedigree a')).map(link => link.href);
|
||||
let response = await setHorsePedigreeAPIAsync(request.data.id, relatedHorses);
|
||||
console.log("Response from API:", response);
|
||||
sendResponse({ success: true, data: response });
|
||||
}
|
||||
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;
|
||||
var response = setHorseTrainingAPI(request.data.id, training);
|
||||
let training = document.querySelector('.top:nth-child(8)') ? document.querySelector('.top:nth-child(8)').innerText : document.querySelector('.top:nth-child(6)').innerText;
|
||||
let response = await setHorseTrainingAPIAsync(request.data.id, training);
|
||||
console.log("Response from API:", response);
|
||||
sendResponse({ success: true, data: response });
|
||||
}
|
||||
|
|
@ -57,20 +57,23 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||
.map(value => parseFloat(value));
|
||||
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);
|
||||
sendResponse({ success: true, data: response });
|
||||
}
|
||||
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));
|
||||
var response = setHorseGeneticsAPI(request.data.id, genetics);
|
||||
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...
|
||||
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);
|
||||
}
|
||||
else if (selectedTab === "Health")
|
||||
{
|
||||
var health = [...document.querySelector("#tab_health2 p").innerText.matchAll(/:\s*(\w+)/g)].map(match => match[1]);
|
||||
var response = setHorseHealthAPI(request.data.id, health);
|
||||
let health = [...document.querySelector("#tab_health2 p").innerText.matchAll(/:\s*(\w+)/g)].map(match => match[1]);
|
||||
let response = setHorseHealthAPI(request.data.id, health);
|
||||
console.log("Response from API:", response);
|
||||
}
|
||||
else
|
||||
|
|
@ -81,9 +84,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||
return true; // This is necessary to allow asynchronous response
|
||||
});
|
||||
function getTabselText() {
|
||||
const tabElement = document.querySelector('div.tabsel');
|
||||
if (tabElement) {
|
||||
return tabElement.textContent.trim();
|
||||
}
|
||||
return null;
|
||||
const tabElement = document.querySelector('div.tabsel').textContent?.trim();
|
||||
return tabElement;
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
// Modell für ein Pferd
|
||||
|
||||
var globalHorse = {
|
||||
// Basic
|
||||
id: null, // ID of the horse
|
||||
|
|
@ -13,27 +14,27 @@ var globalHorse = {
|
|||
// Training
|
||||
training: null, // training of the horse e.g. Basic Training
|
||||
// Genetics
|
||||
GP: 0, // GP of the horse
|
||||
gp: 0, // GP of the horse
|
||||
features: {}, // features of the horse e.g. Dressage, Driving, Endurance etc.
|
||||
// Genes
|
||||
Extension: null, // Extension gene of the horse
|
||||
Agouti: null, // Agouti gene of the horse
|
||||
Grey: null, // Grey gene of the horse
|
||||
Cream: null, // Cream gene of the horse
|
||||
Dun: null, // Dun gene of the horse
|
||||
Champagne: null, // Champagne gene of the horse
|
||||
Silver: null, // Silver gene of the horse
|
||||
Mushroom: null, // Mushroom gene of the horse
|
||||
Frame: null, // Frame gene of the horse
|
||||
Appaloosa: null, // Appaloosa gene of the horse
|
||||
PATN1: null, // PATN1 gene of the horse
|
||||
MITF: null, // MITF gene of the horse
|
||||
SW2: null, // SW2 gene of the horse
|
||||
KIT: null, // KIT gene of the horse
|
||||
extension: null, // Extension gene of the horse
|
||||
agouti: null, // Agouti gene of the horse
|
||||
grey: null, // Grey gene of the horse
|
||||
cream: null, // Cream gene of the horse
|
||||
dun: null, // Dun gene of the horse
|
||||
champagne: null, // Champagne gene of the horse
|
||||
silver: null, // Silver gene of the horse
|
||||
mushroom: null, // Mushroom gene of the horse
|
||||
frame: null, // Frame gene of the horse
|
||||
appaloosa: null, // Appaloosa gene of the horse
|
||||
patn1: null, // PATN1 gene of the horse
|
||||
mitf: null, // MITF gene of the horse
|
||||
sw2: null, // SW2 gene of the horse
|
||||
kit: null, // KIT gene of the horse
|
||||
|
||||
RAB: null, // RAB gene of the horse
|
||||
Seal: null, // Seal gene of the horse
|
||||
Flaxen: null, // Flaxen gene of the horse
|
||||
rab: null, // RAB gene of the horse
|
||||
seal: null, // Seal gene of the horse
|
||||
flaxen: null, // Flaxen gene of the horse
|
||||
|
||||
// Achievements
|
||||
conformation: {}, // conformation of the horse e.g. Walk, Trot, Canter, Gallop, Jumping, Dressage
|
||||
|
|
|
|||
|
|
@ -92,30 +92,68 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||
rowDiv.appendChild(emojiCell);
|
||||
table.appendChild(rowDiv);
|
||||
});
|
||||
const infoTextLoaded = document.createElement('p');
|
||||
infoTextLoaded.textContent = '✅ Loaded';
|
||||
infoTextLoaded.justifyContent = 'space-between';
|
||||
infoTextLoaded.width = '100%';
|
||||
const infoTextDynamic = document.createElement('p');
|
||||
infoTextDynamic.textContent = '☑️ Dynamic';
|
||||
infoTextDynamic.justifyContent = 'space-between';
|
||||
infoTextDynamic.width = '100%';
|
||||
const infoTextNeedRefresh = document.createElement('p');
|
||||
infoTextNeedRefresh.textContent = '🔄 Needs Refresh';
|
||||
infoTextNeedRefresh.justifyContent = 'space-between';
|
||||
infoTextNeedRefresh.width = '100%';
|
||||
const infoTextNotLoaded = document.createElement('p');
|
||||
infoTextNotLoaded.textContent = '❌ Not Loaded';
|
||||
infoTextNotLoaded.justifyContent = 'space-between';
|
||||
infoTextNotLoaded.width = '100%';
|
||||
|
||||
// Button oben hinzufügen, dann die Tabelle
|
||||
// Linie hinzufügen
|
||||
const line = document.createElement('hr');
|
||||
Object.assign(line.style, {
|
||||
width: '100%',
|
||||
border: '0',
|
||||
height: '1px',
|
||||
backgroundColor: '#ddd',
|
||||
margin: '10px 0'
|
||||
});
|
||||
|
||||
// Legend-Titel hinzufügen
|
||||
const legendTitle = document.createElement('div');
|
||||
legendTitle.textContent = 'Legend:';
|
||||
Object.assign(legendTitle.style, {
|
||||
fontWeight: 'bold',
|
||||
fontSize: '14px',
|
||||
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(table);
|
||||
div.appendChild(infoTextLoaded);
|
||||
div.appendChild(infoTextDynamic);
|
||||
div.appendChild(infoTextNotLoaded);
|
||||
div.appendChild(infoTextNeedRefresh);
|
||||
div.appendChild(line);
|
||||
div.appendChild(legendTitle);
|
||||
div.appendChild(legend);
|
||||
banner.appendChild(div);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue