From 8b9985873a01c89a02e83b213539b9eba9aaacac Mon Sep 17 00:00:00 2001 From: zhu <1812073942@qq.com> Date: Wed, 6 May 2026 10:08:17 +0800 Subject: [PATCH] 1 --- manifest.config.ts | 48 ++++++++++++++++++------------------ src/background/domScraper.ts | 4 +-- src/config/platforms.ts | 1 - src/content/App.vue | 8 +++--- src/options/App.vue | 22 ++++++++--------- src/popup/App.vue | 20 +++------------ src/shared/auth.ts | 3 +++ src/types/crawl.ts | 48 ++++++++++++++++++------------------ src/types/platform.ts | 2 -- tsconfig.tsbuildinfo | 2 +- 10 files changed, 71 insertions(+), 87 deletions(-) diff --git a/manifest.config.ts b/manifest.config.ts index 03ab775..f5ab69b 100644 --- a/manifest.config.ts +++ b/manifest.config.ts @@ -1,30 +1,30 @@ -import { defineManifest } from '@crxjs/vite-plugin'; +import {defineManifest} from '@crxjs/vite-plugin'; import pkg from './package.json'; export default defineManifest({ - manifest_version: 3, - name: pkg.name, - version: pkg.version, - icons: { - 48: 'public/logo.png', - }, - action: { - default_icon: { - 48: 'public/logo.png', + manifest_version: 3, + name: pkg.name, + version: pkg.version, + icons: { + 48: 'public/logo.png', }, - default_popup: 'src/popup/index.html', - }, - options_page: 'src/options/index.html', - content_scripts: [ - { - js: ['src/content/main.ts'], - matches: ['https://*/*', 'http://*/*'], + action: { + default_icon: { + 48: 'public/logo.png', + }, + default_popup: 'src/popup/index.html', + }, + options_page: 'src/options/index.html', + content_scripts: [ + { + js: ['src/content/main.ts'], + matches: ['https://*/*', 'http://*/*'], + }, + ], + host_permissions: ['https://*/*', 'http://*/*'], + permissions: ['storage', 'tabs', 'scripting', 'activeTab', 'windows'], + background: { + service_worker: 'src/background/index.ts', + type: 'module', }, - ], - host_permissions: ['https://*/*', 'http://*/*'], - permissions: ['storage', 'tabs', 'scripting', 'activeTab', 'windows'], - background: { - service_worker: 'src/background/index.ts', - type: 'module', - }, }); diff --git a/src/background/domScraper.ts b/src/background/domScraper.ts index 9cb5b11..8e1c1c2 100644 --- a/src/background/domScraper.ts +++ b/src/background/domScraper.ts @@ -3,8 +3,6 @@ import type { PlatformFieldConfig } from '@/types'; /** DOM 抓取后的通用结果结构。 */ export type DomScrapeResult = Record; -/** 默认等待时间,用于点击后或翻页后等待页面渲染。 */ -const DEFAULT_DELAY = 1500; /** * 在目标网页上下文中执行 DOM 抓取。 @@ -22,7 +20,7 @@ export async function scrapeDomFields(fields: PlatformFieldConfig[]): Promise new Promise((resolve) => window.setTimeout(resolve, ms ?? DEFAULT_DELAY)); +const sleep = (ms?: number) => new Promise((resolve) => window.setTimeout(resolve, ms ?? 1500)); /** 从元素中提取实际值,默认取文本,也支持 attr、图片 src、链接 href。 */ function extractValue(el: Element | null, config: PlatformFieldConfig): string | null { diff --git a/src/config/platforms.ts b/src/config/platforms.ts index 4d47666..9401964 100644 --- a/src/config/platforms.ts +++ b/src/config/platforms.ts @@ -5,7 +5,6 @@ export const PLATFORM_CONFIGS: PlatformConfig[] = [ { id: 'Shopee', name: 'Shopee 后台', - baseUrl: 'https://seller.shopee.com.my/', steps: [ { name: '数据看板', diff --git a/src/content/App.vue b/src/content/App.vue index b5ac8f9..882e389 100644 --- a/src/content/App.vue +++ b/src/content/App.vue @@ -1,6 +1,6 @@