document.addEventListener("DOMContentLoaded", function () {
function addSupplierStock() {
const availabilityBox = document.querySelector(".store-availability");
if (!availabilityBox) return;
const table = availabilityBox.querySelector("table tbody");
if (!table) return;
// všechny elementy skladů v HTML produktu
const stocks = document.querySelectorAll("[data-stock-id]");
stocks.forEach(stock => {
const stockName = stock.dataset.stockName;
const stockAmount = stock.dataset.stockAmount;
if (!stockName || !stockAmount) return;
// pokud sklad ještě není v tabulce (tedy pravděpodobně dodavatel)
let alreadyListed = false;
table.querySelectorAll("tr").forEach(row => {
if (row.innerText.includes(stockName)) {
alreadyListed = true;
}
});
if (!alreadyListed) {
const row = document.createElement("tr");
row.innerHTML = `
${stockName}
${stockAmount} ks
`;
table.appendChild(row);
}
});
}
// doplněk se načítá dynamicky → kontrolujeme několikrát
let tries = 0;
const interval = setInterval(function () {
addSupplierStock();
tries++;
if (tries > 10) clearInterval(interval);
}, 500);
});