import{a as e,c as t,f as n,i as r,l as i,m as a,n as o,o as s}from"./pageDetailHtml-CA9cVLla.js";function c(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function l(e){return e==null?``:String(e).trim()}function u(e){return e.replace(/\.jpg_\.webp$/i,`.jpg`).replace(/_\d+x\d+\.jpg$/i,`.jpg`)}function d(e){let t=u(e).toLowerCase();return!(!t.includes(`alicdn.com/img/ibank/`)||t.includes(`_250x250`)||t.endsWith(`.jpg_b.jpg`))}function f(e){let t=e.trim();if(!t)return[];let r=new Set,i=[],o=e=>{let t=e.trim().replace(/^\/\//,`https://`);if(!t||r.has(t))return;let n=u(t);d(n)&&(r.add(n),i.push(n.startsWith(`//`)?`https:${n}`:n))};try{n(t).querySelectorAll(`img[src]`).forEach(e=>{o(e.getAttribute(`src`)??``)})}catch{}if(!i.length){let e=/\bsrc=(["'])(https?:\/\/[^"']+|\/\/[^"']+)\1/gi,n;for(;(n=e.exec(t))!==null;)o(n[2])}return a(i)}function p(e){return c(e)?f(l(e.content)):[]}function m(e){return c(e)?!!l(e.content):!1}function h(e){return e.searchParams.get(`offerId`)||(e.pathname.match(/\/offer\/(\d+)\.html/)?.[1]??``)}function g(e){try{return h(new URL(e??window.location.href)).trim()||null}catch{return null}}async function _(t){let r=await chrome.runtime.sendMessage({type:`FETCH_HTML`,payload:{url:t}});return r?.ok?e(n(r.data),[`img[src*="alicdn"]`,`img[data-src*="alicdn"]`,`img[data-lazy-src*="alicdn"]`],60):[]}function v(e){let n=[],r=new Set;return e.querySelectorAll(`#description #detail img, #detail img`).forEach(e=>{let i=t(e);if(!i)return;let a=C(i);!w(a)||r.has(a)||(r.add(a),n.push(a))}),n}async function y(e){let t=e.trim();if(!t)return[];let r=await chrome.runtime.sendMessage({type:`FETCH_HTML`,payload:{url:`https://detail.1688.com/offer/${t}.html`}});return!r?.ok||typeof r.data!=`string`?[]:v(n(r.data))}var b=[`#gallery img.preview-img`,`#gallery .od-gallery-preview img`,`.detail-gallery img`,`.mod-detail-gallery img`,`.vertical-img img`,`.detail-gallery-thumbnail img`,`.tab-content-container .detail-gallery img`,`.swipe-pane img`,`[class*="detail-gallery"] img`,`[class*="main-img"] img`,`[class*="pic-gallery"] img`],x=[`#detail img`,`.content-detail img`,`#description #detail img`,`#description img`],S=[`#detail`,`.content-detail`,`#description #detail`,`#description`];function C(e){return u(e)}function w(e){return d(e)}function T(e,n){let r=[],i=new Set;for(let n of S)e.querySelectorAll(n).forEach(e=>{e.querySelectorAll(`img`).forEach(e=>{let n=t(e);if(!n)return;let a=C(n);!w(a)||i.has(a)||(i.add(a),r.push(a))})});return a(r).slice(0,n)}function E(e,n){let r=[],i=new Set,o=e=>{e.querySelectorAll(`img`).forEach(e=>{let n=t(e);if(!n)return;let a=C(n);!w(a)||i.has(a)||(i.add(a),r.push(a))})},s=e.getElementById(`detail`);s&&o(s);let c=e.getElementsByClassName(`content-detail`);for(let e of Array.from(c))o(e);return e.querySelectorAll(`*`).forEach(e=>{let t=e.shadowRoot;if(!t)return;let n=t.getElementById(`detail`);n&&o(n),t.querySelectorAll(`.content-detail`).forEach(e=>o(e))}),a(r).slice(0,n)}var D=[`[class*="sku"] img`,`[class*="obj-sku"] img`,`.obj-sku img`,`[class*="spec"] img`,`.sku-item img`,`[class*="offer-sku"] img`,`[class*="sku-item"] img`],O=[`[class*="sku"]`,`[class*="obj-sku"]`,`[class*="spec-item"]`,`.sku-item`],k={key:`1688`,match:e=>e.hostname===`detail.1688.com`,extractProduct:(t,n)=>{let o=h(n),c=i(t,[`#productTitle .title-content h1`,`#productTitle h1`,`[data-module="od_title"] h1`,`.module-od-title h1`,`h1.d-title`,`.title-text`,`h1`]),l=t.querySelector(`.price-comp`)?.textContent?.trim()??``,u=i(t,[`.detail-desc-decorate-richtext`,`.desc-lazyload-container`,`[class*="detail-desc"]`]),d=Array.from(t.querySelectorAll(`.obj-content li, .sku-item, [class*="spec"] li`)).map(e=>e.textContent?.trim()??``).filter(Boolean).slice(0,10),f=e(t,b,40).map(C).filter(w),p=a([...e(t,x,80),...T(t,100),...E(t,160)]).map(C).filter(w),m=e(t,D,30);m=a([...m,...r(t,O,20)]);let g=e(t,[`[class*="comment"] img`,`[class*="feedback"] img`,`[class*="evaluate"] img`],20),_=s(f,p,m);return f=_.main,p=_.detail,m=_.sku,{id:o,sourceSite:`1688`,url:n.href,title:c||`1688 商品`,priceText:l,description:u,specs:d,mainImages:f,detailImages:p,skuImages:m,commentImages:g}},extractCommentImages:t=>e(t,[`[class*="comment"] img`,`[class*="feedback"] img`,`[class*="evaluate"] img`],30),fetchExtraCommentImagesById:async e=>e?a((await _(`https://detail.1688.com/offer/${e}.html`)).filter(e=>e.toLowerCase().includes(`comment`)||e.includes(`rate`))):[],extractDetailHtml:e=>o(e,S)};export{m as a,p as i,y as n,g as r,k as t};