1
This commit is contained in:
@@ -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',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -3,8 +3,6 @@ import type { PlatformFieldConfig } from '@/types';
|
||||
/** DOM 抓取后的通用结果结构。 */
|
||||
export type DomScrapeResult = Record<string, unknown>;
|
||||
|
||||
/** 默认等待时间,用于点击后或翻页后等待页面渲染。 */
|
||||
const DEFAULT_DELAY = 1500;
|
||||
|
||||
/**
|
||||
* 在目标网页上下文中执行 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。 */
|
||||
function extractValue(el: Element | null, config: PlatformFieldConfig): string | null {
|
||||
|
||||
@@ -5,7 +5,6 @@ export const PLATFORM_CONFIGS: PlatformConfig[] = [
|
||||
{
|
||||
id: 'Shopee',
|
||||
name: 'Shopee 后台',
|
||||
baseUrl: 'https://seller.shopee.com.my/',
|
||||
steps: [
|
||||
{
|
||||
name: '数据看板',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||
import type { CrawlTaskState } from '@/types';
|
||||
import {computed, onMounted, onUnmounted, ref} from 'vue';
|
||||
import type {CrawlTaskState} from '@/types';
|
||||
|
||||
/** 当前后台保存的爬取任务快照,用于决定是否展示右下角浮窗。 */
|
||||
const crawlState = ref<CrawlTaskState | null>(null);
|
||||
@@ -33,7 +33,7 @@ onUnmounted(() => {
|
||||
/** 从 background 获取最新爬取任务状态,并在任务结束时自动收起面板。 */
|
||||
async function refreshCrawlState() {
|
||||
/** background 返回的当前爬取任务状态响应。 */
|
||||
const response = await sendBackgroundMessage<CrawlTaskState | null>({ action: 'GET_CRAWL_STATE' });
|
||||
const response = await sendBackgroundMessage<CrawlTaskState | null>({action: 'GET_CRAWL_STATE'});
|
||||
|
||||
if (response.ok) {
|
||||
crawlState.value = response.data ?? null;
|
||||
@@ -80,7 +80,7 @@ function getStepText(status: string): string {
|
||||
/** 发送消息到 background;非扩展环境下返回空成功响应,方便本地页面不报错。 */
|
||||
function sendBackgroundMessage<T>(message: unknown): Promise<{ ok: boolean; data?: T; error?: string }> {
|
||||
if (typeof chrome === 'undefined' || !chrome.runtime?.sendMessage) {
|
||||
return Promise.resolve({ ok: true, data: null as T });
|
||||
return Promise.resolve({ok: true, data: null as T});
|
||||
}
|
||||
|
||||
return chrome.runtime.sendMessage(message);
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
<template>
|
||||
<main class="page">
|
||||
<h1>店闪设置</h1>
|
||||
<p>当前版本先以内置平台配置和 popup 控制为主,这里预留给后续高级设置。</p>
|
||||
</main>
|
||||
<main class="page">
|
||||
<h1>店闪设置</h1>
|
||||
<p>当前版本先以内置平台配置和 popup 控制为主,这里预留给后续高级设置。</p>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
padding: 32px;
|
||||
font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
|
||||
background: #f5efe3;
|
||||
color: #193144;
|
||||
min-height: 100vh;
|
||||
padding: 32px;
|
||||
font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
|
||||
background: #f5efe3;
|
||||
color: #193144;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0 0 12px;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -13,12 +13,6 @@ const crawlState = ref<CrawlTaskState | null>(null);
|
||||
const elapsedSeconds = ref(0);
|
||||
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(() =>
|
||||
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);
|
||||
}
|
||||
|
||||
function getRuntimeManifest(): chrome.runtime.Manifest | null {
|
||||
if (typeof chrome === 'undefined' || !chrome.runtime?.getManifest) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return chrome.runtime.getManifest();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="w-80 bg-slate-50 text-slate-900">
|
||||
<section class="flex min-h-64 flex-col gap-5 p-5">
|
||||
<header class="space-y-2">
|
||||
<p class="text-lg font-semibold leading-6">{{ extensionName }}</p>
|
||||
<p class="text-sm leading-5 text-slate-600">{{ extensionDescription }}</p>
|
||||
<p class="text-lg font-semibold leading-6">店闪</p>
|
||||
<p class="text-sm leading-5 text-slate-600">自动打开商家后台,按平台配置顺序采集页面数据</p>
|
||||
</header>
|
||||
|
||||
<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>
|
||||
<span v-else></span>
|
||||
<span>v{{ extensionVersion }}</span>
|
||||
<span>v1.0.0</span>
|
||||
</footer>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
@@ -43,6 +43,9 @@ async function setToken(token: string): Promise<void> {
|
||||
window.localStorage.setItem(AUTH_TOKEN_KEY, token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取谷歌缓存
|
||||
*/
|
||||
function getChromeStorage(): chrome.storage.StorageArea | null {
|
||||
if (typeof chrome === 'undefined' || !chrome.storage?.local) {
|
||||
return null;
|
||||
|
||||
@@ -12,34 +12,34 @@ export type CrawlTaskStatus = 'running' | 'completed' | 'failed' | 'canceled';
|
||||
* 时间轴中的单个爬取步骤进度。
|
||||
*/
|
||||
export interface CrawlProgressStep {
|
||||
/** 步骤名称,用于展示给用户。 */
|
||||
name: string;
|
||||
/** 步骤唯一标识,对应平台配置 steps 中的 uniqueKey。 */
|
||||
uniqueKey: string;
|
||||
/** 当前步骤执行状态。 */
|
||||
status: CrawlStepStatus;
|
||||
/** 状态补充说明,如失败原因。 */
|
||||
message?: string;
|
||||
/** 步骤名称,用于展示给用户。 */
|
||||
name: string;
|
||||
/** 步骤唯一标识,对应平台配置 steps 中的 uniqueKey。 */
|
||||
uniqueKey: string;
|
||||
/** 当前步骤执行状态。 */
|
||||
status: CrawlStepStatus;
|
||||
/** 状态补充说明,如失败原因。 */
|
||||
message?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前正在执行的爬取任务快照,供 popup 和 content script 同步展示。
|
||||
*/
|
||||
export interface CrawlTaskState {
|
||||
/** 任务唯一标识。 */
|
||||
id: string;
|
||||
/** 当前爬取平台 ID。 */
|
||||
platformId: string;
|
||||
/** 当前爬取平台名称。 */
|
||||
platformName: string;
|
||||
/** 爬取窗口 ID,由 background 创建窗口后写入。 */
|
||||
windowId?: number;
|
||||
/** 任务开始时间戳。 */
|
||||
startedAt: number;
|
||||
/** 当前任务状态。 */
|
||||
status: CrawlTaskStatus;
|
||||
/** 当前执行到的步骤下标。 */
|
||||
currentStepIndex: number;
|
||||
/** 平台 steps 映射出的时间轴进度。 */
|
||||
steps: CrawlProgressStep[];
|
||||
/** 任务唯一标识。 */
|
||||
id: string;
|
||||
/** 当前爬取平台 ID。 */
|
||||
platformId: string;
|
||||
/** 当前爬取平台名称。 */
|
||||
platformName: string;
|
||||
/** 爬取窗口 ID,由 background 创建窗口后写入。 */
|
||||
windowId?: number;
|
||||
/** 任务开始时间戳。 */
|
||||
startedAt: number;
|
||||
/** 当前任务状态。 */
|
||||
status: CrawlTaskStatus;
|
||||
/** 当前执行到的步骤下标。 */
|
||||
currentStepIndex: number;
|
||||
/** 平台 steps 映射出的时间轴进度。 */
|
||||
steps: CrawlProgressStep[];
|
||||
}
|
||||
|
||||
@@ -95,8 +95,6 @@ export interface PlatformConfig {
|
||||
id: string;
|
||||
/** 平台显示名称。 */
|
||||
name: string;
|
||||
/** 平台后台首页或默认入口地址。 */
|
||||
baseUrl: string;
|
||||
/** 当前平台的页面抓取顺序。 */
|
||||
steps: PlatformStepConfig[];
|
||||
}
|
||||
|
||||
@@ -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"}
|
||||
Reference in New Issue
Block a user