The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
feat(extension): 增强图片嗅探,支持 CSS 背景图和全文正则
XiaoYouChR2429f9deca04
diff --git a/browser_extension/app/src/popup/components/ImageCard.tsx b/browser_extension/app/src/popup/components/ImageCard.tsxindex 0cdd9d7c..5fb522be 100644--- a/browser_extension/app/src/popup/components/ImageCard.tsx+++ b/browser_extension/app/src/popup/components/ImageCard.tsx@@ -51,13 +51,16 @@ export function ImageCard({ext,selected,onSelectedChange,+ onDimensionsLoaded,}: {image: ScannedImage;ext: string;selected?: boolean;onSelectedChange?: (checked: boolean) => void;+ onDimensionsLoaded?: (src: string, w: number, h: number) => void;}) {const styles = useStyles();+ const hasDimensions = image.naturalWidth > 0 && image.naturalHeight > 0;return (<div@@ -69,6 +72,12 @@ export function ImageCard({className={styles.thumbnail}loading="lazy"src={image.src}+ onLoad={hasDimensions ? undefined : (e) => {+ const el = e.currentTarget;+ if (el.naturalWidth > 0 && el.naturalHeight > 0) {+ onDimensionsLoaded?.(image.src, el.naturalWidth, el.naturalHeight);+ }+ }}/><Checkboxchecked={selected}@@ -76,7 +85,9 @@ export function ImageCard({onChange={(e) => e.stopPropagation()}/><div className={styles.info}>- {`${image.naturalWidth}×${image.naturalHeight} · ${ext}`}+ {hasDimensions+ ? `${image.naturalWidth}×${image.naturalHeight} · ${ext}`+ : ext}</div></div>);diff --git a/browser_extension/app/src/popup/pages/ImagesPage.tsx b/browser_extension/app/src/popup/pages/ImagesPage.tsxindex 44054d7f..b29bf090 100644--- a/browser_extension/app/src/popup/pages/ImagesPage.tsx+++ b/browser_extension/app/src/popup/pages/ImagesPage.tsx@@ -200,6 +200,12 @@ export function ImagesPage({});}, [filteredImages]);+ function updateDimensions(src: string, w: number, h: number) {+ setImages((prev) => prev.map((img) =>+ img.src === src ? { ...img, naturalWidth: w, naturalHeight: h } : img,+ ));+ }+function toggleImage(src: string) {setSelectedSrcs((current) => {const next = new Set(current);@@ -349,6 +355,7 @@ export function ImagesPage({ext={image.ext}selected={selectedSrcs.has(image.src)}onSelectedChange={() => toggleImage(image.src)}+ onDimensionsLoaded={updateDimensions}/>))}</div>diff --git a/browser_extension/app/src/popup/scan-images.ts b/browser_extension/app/src/popup/scan-images.tsindex afd254a0..246d33d5 100644--- a/browser_extension/app/src/popup/scan-images.ts+++ b/browser_extension/app/src/popup/scan-images.ts@@ -2,22 +2,43 @@ import type {ScannedImage} from "../shared/types";const IMAGE_REFERER_RULE_ID = 9999;+const IMAGE_EXT_RE = /\.(png|jpg|jpeg|gif|webp|svg|bmp|ico|avif|heic|tif|tiff|apng|jfif)(\?.*)?$/i;+const URL_RE = /https?:\/\/[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b[-a-zA-Z0-9@:%_+.~#?&/=]*/gi;+const BG_URL_RE = /url\(\s*['"]?\s*(\S+?)\s*['"]?\s*\)/i;+function scanPageImages(): ScannedImage[] {const seen = new Set<string>();const results: ScannedImage[] = [];+ function add(src: string, w: number, h: number, alt: string): void {+ if (!src || src.startsWith("data:") || src.startsWith("blob:") || seen.has(src)) return;+ seen.add(src);+ results.push({ src, naturalWidth: w, naturalHeight: h, alt });+ }++ // <img> naturalWidth/Height is free here — the page already loaded these imagesfor (const img of Array.from(document.querySelectorAll<HTMLImageElement>("img"))) {const src = img.currentSrc || img.src;- if (!src || src.startsWith("data:") || src.startsWith("blob:") || seen.has(src)) {- continue;+ add(src, img.naturalWidth, img.naturalHeight, img.alt || "");+ }++ const pseudos: (string | null)[] = [null, "::before", "::after"];+ for (const el of Array.from(document.querySelectorAll("*"))) {+ for (const pseudo of pseudos) {+ const bg = getComputedStyle(el, pseudo).getPropertyValue("background-image");+ if (bg === "none" || !bg) continue;+ const m = BG_URL_RE.exec(bg);+ if (m?.[1]) add(m[1], 0, 0, "");}- const w = img.naturalWidth;- const h = img.naturalHeight;- if (w === 0 || h === 0) {- continue;+ }++ const html = document.documentElement.outerHTML;+ const urls = html.match(URL_RE);+ if (urls) {+ for (const raw of new Set(urls)) {+ const cleaned = raw.replace(/&(quot|lt|gt|amp);?$/i, "");+ if (IMAGE_EXT_RE.test(cleaned)) add(cleaned, 0, 0, "");}- seen.add(src);- results.push({ src, naturalWidth: w, naturalHeight: h, alt: img.alt || "" });}return results;