Galaxy S25 Ultra
await fetch('https://api.shop.samsung.com/tokocommercewebservices/v2/' + sitecode + '/products?productCodes=' + sku)
.then((response) => response.json())
.then((data) => {
console.log(data, 'json')
for (var c = 0; c < data.length; c++) {
//console.log(data,'results');
if (data[c].stock != null) {
var stockLevels = data[c].stock.stockLevel;
//console.log("stockLevels",stockLevels);
if (stockLevels > 0) {
var stockmessgaecheck = document.querySelectorAll('.s-in-stock');
if (stockmessgaecheck) {
if (stockmessgaecheck.length > 0) {
document.querySelector('.s-in-stock').remove();
}
}
var stockboxes = document.querySelectorAll('.s-option-storage li.hubble-product__options-list .s-option-box.is-checked');
var stockbox = stockboxes[0].nextElementSibling;
var stockmessgae = document.createElement("span");
stockmessgae.setAttribute("class", "s-in-stock ico-type");
stockmessgae.innerHTML = '
Na sklade';
var selected = document.querySelectorAll('.s-option-storage .hubble-product__options-content li.hubble-product__options-list .s-option-box.is-checked');
var parent = selected[0].nextElementSibling;
parent.insertAdjacentElement("beforeend", stockmessgae);
parent.style.display = 'block';
}
if (stockLevels == null) {
if (data[c].stock.stockLevelStatus) {
//console.log("stock",data[c].stock.stockLevelStatus)
if (data[c].stock.stockLevelStatus == 'inStock') {
var stockmessgaecheck = document.querySelectorAll('.s-in-stock');
if (stockmessgaecheck) {
if (stockmessgaecheck.length > 0) {
document.querySelector('.s-in-stock').remove();
}
}
var stockboxes = document.querySelectorAll('.s-option-storage li.hubble-product__options-list .s-option-box.is-checked');
var stockbox = stockboxes[0].nextElementSibling;
var stockmessgae = document.createElement("span");
stockmessgae.setAttribute("class", "s-in-stock ico-type");
stockmessgae.innerHTML = ' Na sklade';
var selected = document.querySelectorAll('.s-option-storage .hubble-product__options-content li.hubble-product__options-list .s-option-box.is-checked');
var parent = selected[0].nextElementSibling;
parent.insertAdjacentElement("beforeend", stockmessgae);
parent.style.display = 'block';
}
}
}
}
if (data[c].stock == null) {
var selected = document.querySelectorAll('.s-option-storage.hubble-product__options-content li.hubble-product__options-list .s-option-box');
if(selected.length> 0){
var active = selected[c].classList.contains("is-checked");
if (active) {
var parent = selected[c].nextElementSibling;
parent.style.display = 'none';
}
}
}
}
});
};
var getproductskus = document.querySelectorAll('div.s-option-box.hubble-pd-radio.js-radio-wrap.is-checked input[data-typecode=OPT-015]');
var productsku = getproductskus[0].getAttribute('data-modelcode');
//console.log(productsku);
getStock(productsku);
// Get the input box element
const inputBox = document.querySelector(`div.s-option-box.hubble-pd-radio.js-radio-wrap.is-checked input[data-typecode=OPT-015]`);
const deviceBox = document.querySelector('div.s-option-box.hubble-pd-radio.js-radio-wrap.is-checked input[data-typecode=OPT-007]');
//console.log(inputBox);
// Create a new MutationObserver instance
const observer = new MutationObserver((mutationsList, observer) => {
// Loop through each mutation in the mutations list
for (const mutation of mutationsList) {
// Check if the mutation type is an attribute change
if (mutation.attributeName === 'data-modelcode' ) {
// Check if the changed attribute is on the input box
if (mutation.target === inputBox) {
// Log a message to the console
console.log('Input box attribute changed:', mutation.attributeName);
var getproductskus = document.querySelectorAll('div.s-option-box.hubble-pd-radio.js-radio-wrap.is-checked input[data-typecode=OPT-015]');
//console.log(getproductskus);
let sku = getproductskus[0].getAttribute('data-modelcode');
//console.log(sku, 'sku');
getStock(sku);
}
}
}
});
// Start observing the input box for attribute changes
observer.observe(inputBox, { attributes: true, attributeOldValue: true , characterData: true , childList: true});
});