36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
(function () {
|
|
const waitForRunParams = (timeout = 5000) => {
|
|
return new Promise((res) => {
|
|
const start = Date.now();
|
|
const check = () => {
|
|
if (window.runParams && Object.keys(window.runParams).length > 0) {
|
|
return res(window.runParams);
|
|
}
|
|
if (Date.now() - start > timeout) return res(null);
|
|
requestAnimationFrame(check);
|
|
};
|
|
check();
|
|
});
|
|
};
|
|
|
|
(async () => {
|
|
const runParams = await waitForRunParams();
|
|
const result = {
|
|
title: document.querySelector('[data-pl="product-title"]')?.innerText || '',
|
|
images: runParams?.imageModule?.imagePathList || [],
|
|
specs: {},
|
|
description: ''
|
|
};
|
|
|
|
const specsData = runParams?.specifications || runParams?.productInfoComponent?.specifications || [];
|
|
specsData.forEach(group => {
|
|
(group.attributes || []).forEach(attr => {
|
|
result.specs[attr.attrName] = attr.attrValue;
|
|
});
|
|
});
|
|
|
|
// שלח חזרה לתוסף
|
|
window.postMessage({ type: 'FROM_INJECTED', data: result }, '*');
|
|
})();
|
|
})();
|