This commit is contained in:
zhu
2026-05-06 10:08:17 +08:00
parent 4c0a1d8151
commit 8b9985873a
10 changed files with 71 additions and 87 deletions

View File

@@ -3,8 +3,6 @@ import type { PlatformFieldConfig } from '@/types';
/** DOM 抓取后的通用结果结构。 */ /** DOM 抓取后的通用结果结构。 */
export type DomScrapeResult = Record<string, unknown>; export type DomScrapeResult = Record<string, unknown>;
/** 默认等待时间,用于点击后或翻页后等待页面渲染。 */
const DEFAULT_DELAY = 1500;
/** /**
* 在目标网页上下文中执行 DOM 抓取。 * 在目标网页上下文中执行 DOM 抓取。
@@ -22,7 +20,7 @@ export async function scrapeDomFields(fields: PlatformFieldConfig[]): Promise<Do
/** 睡眠工具,给点击、翻页、异步渲染留出等待时间。 */ /** 睡眠工具,给点击、翻页、异步渲染留出等待时间。 */
const sleep = (ms?: number) => new Promise((resolve) => window.setTimeout(resolve, ms ?? DEFAULT_DELAY)); const sleep = (ms?: number) => new Promise((resolve) => window.setTimeout(resolve, ms ?? 1500));
/** 从元素中提取实际值,默认取文本,也支持 attr、图片 src、链接 href。 */ /** 从元素中提取实际值,默认取文本,也支持 attr、图片 src、链接 href。 */
function extractValue(el: Element | null, config: PlatformFieldConfig): string | null { function extractValue(el: Element | null, config: PlatformFieldConfig): string | null {

View File

@@ -5,7 +5,6 @@ export const PLATFORM_CONFIGS: PlatformConfig[] = [
{ {
id: 'Shopee', id: 'Shopee',
name: 'Shopee 后台', name: 'Shopee 后台',
baseUrl: 'https://seller.shopee.com.my/',
steps: [ steps: [
{ {
name: '数据看板', name: '数据看板',

View File

@@ -13,12 +13,6 @@ const crawlState = ref<CrawlTaskState | null>(null);
const elapsedSeconds = ref(0); const elapsedSeconds = ref(0);
let timer: number | undefined; let timer: number | undefined;
const manifest = getRuntimeManifest();
const extensionName = manifest?.name ?? '店闪';
const extensionVersion = manifest?.version ?? '0.0.0';
const extensionDescription =
manifest?.description || '自动打开商家后台,按平台配置顺序采集页面数据。';
const selectedPlatform = computed(() => const selectedPlatform = computed(() =>
PLATFORM_CONFIGS.find((platform) => platform.id === selectedPlatformId.value) ?? null, PLATFORM_CONFIGS.find((platform) => platform.id === selectedPlatformId.value) ?? null,
); );
@@ -146,22 +140,14 @@ function sendBackgroundMessage<T>(message: unknown): Promise<{ ok: boolean; data
return chrome.runtime.sendMessage(message); return chrome.runtime.sendMessage(message);
} }
function getRuntimeManifest(): chrome.runtime.Manifest | null {
if (typeof chrome === 'undefined' || !chrome.runtime?.getManifest) {
return null;
}
return chrome.runtime.getManifest();
}
</script> </script>
<template> <template>
<main class="w-80 bg-slate-50 text-slate-900"> <main class="w-80 bg-slate-50 text-slate-900">
<section class="flex min-h-64 flex-col gap-5 p-5"> <section class="flex min-h-64 flex-col gap-5 p-5">
<header class="space-y-2"> <header class="space-y-2">
<p class="text-lg font-semibold leading-6">{{ extensionName }}</p> <p class="text-lg font-semibold leading-6">店闪</p>
<p class="text-sm leading-5 text-slate-600">{{ extensionDescription }}</p> <p class="text-sm leading-5 text-slate-600">自动打开商家后台按平台配置顺序采集页面数据</p>
</header> </header>
<div v-if="isLoading" class="rounded-md border border-slate-200 bg-white px-3 py-4 text-sm text-slate-500"> <div v-if="isLoading" class="rounded-md border border-slate-200 bg-white px-3 py-4 text-sm text-slate-500">
@@ -236,7 +222,7 @@ function getRuntimeManifest(): chrome.runtime.Manifest | null {
退出 退出
</button> </button>
<span v-else></span> <span v-else></span>
<span>v{{ extensionVersion }}</span> <span>v1.0.0</span>
</footer> </footer>
</section> </section>
</main> </main>

View File

@@ -43,6 +43,9 @@ async function setToken(token: string): Promise<void> {
window.localStorage.setItem(AUTH_TOKEN_KEY, token); window.localStorage.setItem(AUTH_TOKEN_KEY, token);
} }
/**
* 获取谷歌缓存
*/
function getChromeStorage(): chrome.storage.StorageArea | null { function getChromeStorage(): chrome.storage.StorageArea | null {
if (typeof chrome === 'undefined' || !chrome.storage?.local) { if (typeof chrome === 'undefined' || !chrome.storage?.local) {
return null; return null;

View File

@@ -95,8 +95,6 @@ export interface PlatformConfig {
id: string; id: string;
/** 平台显示名称。 */ /** 平台显示名称。 */
name: string; name: string;
/** 平台后台首页或默认入口地址。 */
baseUrl: string;
/** 当前平台的页面抓取顺序。 */ /** 当前平台的页面抓取顺序。 */
steps: PlatformStepConfig[]; steps: PlatformStepConfig[];
} }

View File

@@ -1 +1 @@
{"root":["./manifest.config.ts","./message.js","./vite.config.ts","./src/background/domscraper.ts","./src/background/index.ts","./src/background/service.ts","./src/background/types.ts","./src/config/platforms.ts","./src/content/app.vue","./src/content/main.ts","./src/options/app.vue","./src/options/main.ts","./src/popup/app.vue","./src/popup/main.ts","./src/shared/auth.ts","./src/types/crawl.ts","./src/types/index.ts","./src/types/platform.ts"],"version":"5.9.3"} {"root":["./manifest.config.ts","./message.js","./vite.config.ts","./src/background/domscraper.ts","./src/background/index.ts","./src/background/service.ts","./src/background/types.ts","./src/background/service/crawl.ts","./src/background/service/lifecycle.ts","./src/background/service/state.ts","./src/background/service/tab.ts","./src/config/platforms.ts","./src/content/app.vue","./src/content/main.ts","./src/options/app.vue","./src/options/main.ts","./src/popup/app.vue","./src/popup/main.ts","./src/shared/auth.ts","./src/types/crawl.ts","./src/types/index.ts","./src/types/platform.ts"],"version":"5.9.3"}