window.OzonStrategies=window.OzonStrategies||{},window.OzonStrategies.taobao={name:"Taobao/Tmall",matches:e=>e.includes("item.taobao.com")||e.includes("detail.tmall.com"),scrape:function(){const e=e=>{if(!e)return null;if(e.includes("url(")){const t=e.match(/url\((?:['"]?)(.*?)(?:['"]?)\)/);t&&t[1]&&(e=t[1])}let t=e.split("?")[0];return t=t.replace(/(\.(?:png|jpg|jpeg|bmp|gif))_?\.?(?:jpg|webp|png)$/i,"$1"),t=t.replace(/_q\d+(?:\.jpg)?$/i,""),t=t.replace(/_\d+x\d+.*$/i,""),t=t.replace(/\.webp$/i,"").replace(/_\.webp$/i,"").replace(/_\.jpg$/i,"").replace(/\.jpg_$/i,".jpg"),t.match(/\.(gif|svg)$/i)||t.includes("s.gif")||t.includes("assets/")||t.includes("empty.png")||t.includes("tps-2-2.png")||t.includes("grey.gif")?null:(t.startsWith("//")&&(t="https:"+t),/\.(jpg|jpeg|png|bmp)$/i.test(t)||(t+=".jpg"),t)},t=(e,t=document)=>{const n=t.querySelector(e);return n?n.innerText.trim():""},n=t('#tbpcDetail_SkuPanelBody span[class*="mainTitle--"]')||document.title,a=[];document.querySelectorAll('[data-tabindex="1"] [class*="generalParamsInfoWrap"] [class*="generalParamsInfoItem"]').forEach(e=>{const t=e.querySelector('[class*="generalParamsInfoItemTitle--"]'),n=e.querySelector('[class*="generalParamsInfoItemSubTitle--"]');t&&n&&a.push({name:t.title||t.innerText,value:n.title||n.innerText})});const l=[];if(document.querySelectorAll('#picGalleryEle [class*="thumbnails"] [class*="thumbnail"] img').forEach(t=>{const n=t.src||t.getAttribute("data-src"),a=e(n);a&&l.push(a)}),0===l.length){const t=document.querySelector("img#main-img, .magnifier-main-img");t&&l.push(e(t.src))}const c=[];let s="";const r=document.querySelector("#imageTextInfo-content .descV8-container")||document.querySelector("#description");r&&(s=r.innerText.slice(0,500).replace(/\s+/g," "),r.querySelectorAll("img").forEach(t=>{const n=t.src||t.getAttribute("data-src"),a=e(n);a&&!c.includes(a)&&c.push(a)}));let i="0";const o=document.querySelector('[class*="priceText--"]')||document.querySelector('[class*="Price--"]');o&&(i=o.innerText.replace(/[^\d.]/g,""));const m=[],u=[];document.querySelectorAll('#skuOptionsArea [class*="skuItem"]').forEach(n=>{const a=t('[class*="ItemLabel"] span',n)||"属性",l=[];n.querySelectorAll('[class*="valueItem--"]').forEach(n=>{const a=t('[class*="valueItemText--"]',n)||n.title,c=n.querySelector('img[class*="valueItemImg--"]'),s=c?e(c.src):null;a&&l.push({name:a,image:s})}),l.length>0&&u.push({label:a,options:l})});let g=-1;for(let h=0;h<u.length;h++)if(u[h].options.some(e=>e.image)){g=h;break}-1===g&&u.length>0&&(g=0);let p=[],d=[];if(-1!==g){p=u[g].options;const e=u.filter((e,t)=>t!==g);d=e.length>0?function(e){if(0===e.length)return[{name:"默认"}];const t=(e,n)=>{if(0===n.length)return e.map(e=>({name:e.name}));const a=n[0],l=t(a.options,n.slice(1)),c=[];return e.forEach(e=>{l.forEach(t=>{c.push({name:`${e.name} ${t.name}`})})}),c};return t(e[0].options,e.slice(1))}(e):[{name:"均码"}]}else p=[{name:"默认",image:l[0]}],d=[{name:"均码"}];let _=1;return p.forEach(e=>{d.forEach(t=>{m.push({row_id:_++,sku_unique_id:`sku_tb_${Date.now()}_${_}`,specs:{color_name_cn:e.name,size_name_cn:t.name},price:{amount:i,currency:"CNY"},stock_quantity:999,sku_image_url:e.image||l[0]})})}),{__instruction__:"Taobao Generic -> Ozon",meta_info:{source_url:window.location.href,crawl_timestamp:Date.now()},global_data:{product_name:n,description_clean_text:s,category_hint:"",features:a,packaging:{defaults:{weight_g:500,length_mm:300,width_mm:200,height_mm:100},full_table:[]},media_gallery:{main_images:[...new Set(l)],detail_images:[...new Set(c)]}},sku_matrix:m}}};
