document.addEventListener("DOMContentLoaded", async () => { const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }); chrome.scripting.executeScript({ target: { tabId: tab.id }, func: () => { return new Promise((resolve) => { try { const title = document.querySelector('[data-pl="product-title"]')?.innerText || ''; let images = []; let specs = {}; // חפש סקריפט שמכיל runParams const scripts = Array.from(document.scripts); const runParamsScript = scripts.find(s => s.textContent.includes('runParams')); if (runParamsScript) { // --- תמונות --- const match = runParamsScript.textContent.match(/"imagePathList":\[(.*?)\]/s); if (match && match[1]) { images = match[1] .split(',') .map(url => url.replace(/"/g, '').trim()) .filter(url => url.startsWith('https')); } // --- מאפיינים (specs) --- const specsMatch = runParamsScript.textContent.match(/"specifications":(\[.*?\])\s*,\s*"props"/s); if (specsMatch && specsMatch[1]) { try { const raw = specsMatch[1] .replace(/([{,])(\s*)(\w+)(\s*):/g, '$1"$3":') // מוסיף גרשיים למפתחות .replace(/'/g, '"'); // מחליף גרשיים בודדים const specsJson = JSON.parse(raw); specsJson.forEach(group => { (group.attributes || []).forEach(attr => { specs[attr.attrName] = attr.attrValue; }); }); } catch (e) { console.log("Failed to parse specs JSON:", e); } } } resolve({ title, images, description: '', // ניתן להוסיף בשלב הבא specs }); } catch (err) { console.error("Error extracting AliExpress data:", err); resolve({ title: '', images: [], specs: {}, description: '' }); } }); } }, (results) => { const data = results?.[0]?.result || {}; const output = document.getElementById("output"); output.textContent = JSON.stringify(data, null, 2); document.getElementById("copyBtn").onclick = () => { navigator.clipboard.writeText(output.textContent); alert("Copied!"); }; }); });