chore: bootstrap mv3 extension project

This commit is contained in:
admin123 2026-04-20 19:50:05 +08:00
parent b04d018840
commit 74a2eca0ac
7 changed files with 3334 additions and 0 deletions

3221
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

18
package.json Normal file
View File

@ -0,0 +1,18 @@
{
"name": "market-plugin-impl",
"version": "0.0.0",
"description": "Bootstrap for the Xingtu market Chrome MV3 extension.",
"private": true,
"scripts": {
"build": "node scripts/build.mjs",
"test": "vitest run --passWithNoTests",
"test:watch": "vitest --passWithNoTests"
},
"license": "UNLICENSED",
"devDependencies": {
"jsdom": "^29.0.2",
"tsup": "^8.5.1",
"typescript": "^6.0.3",
"vitest": "^4.1.4"
}
}

35
scripts/build.mjs Normal file
View File

@ -0,0 +1,35 @@
import { cp, mkdir, rm } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { build } from "tsup";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const projectRoot = path.resolve(__dirname, "..");
const distDir = path.join(projectRoot, "dist");
await rm(distDir, { recursive: true, force: true });
await mkdir(path.join(distDir, "content"), { recursive: true });
await build({
entry: {
index: path.join(projectRoot, "src/content/index.ts")
},
format: ["iife"],
globalName: "StarChartSearchEnhancer",
platform: "browser",
target: "chrome114",
outDir: path.join(distDir, "content"),
clean: false,
splitting: false,
sourcemap: false,
minify: false,
outExtension() {
return { js: ".js" };
}
});
await cp(
path.join(projectRoot, "src/manifest.json"),
path.join(distDir, "manifest.json")
);

21
src/content/index.ts Normal file
View File

@ -0,0 +1,21 @@
const MARKET_ORIGIN = "https://xingtu.cn";
const MARKET_PATH_PREFIX = "/ad/creator/market";
function isMarketPage(locationUrl: URL): boolean {
return (
locationUrl.origin === MARKET_ORIGIN &&
locationUrl.pathname.startsWith(MARKET_PATH_PREFIX)
);
}
function bootstrap(): void {
const locationUrl = new URL(window.location.href);
if (!isMarketPage(locationUrl)) {
return;
}
console.debug("[star-chart-search-enhancer] content script bootstrapped");
}
bootstrap();

13
src/manifest.json Normal file
View File

@ -0,0 +1,13 @@
{
"manifest_version": 3,
"name": "Star Chart Search Enhancer",
"version": "0.0.0",
"description": "Bootstraps the Xingtu creator market content script.",
"content_scripts": [
{
"matches": ["https://xingtu.cn/ad/creator/market*"],
"js": ["content/index.js"],
"run_at": "document_idle"
}
]
}

16
tsconfig.json Normal file
View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "ES2022",
"lib": ["DOM", "ES2022"],
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"noEmit": true,
"isolatedModules": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"skipLibCheck": true,
"types": ["vitest/globals"]
},
"include": ["src/**/*.ts", "tests/**/*.ts", "vitest.config.ts"]
}

10
vitest.config.ts Normal file
View File

@ -0,0 +1,10 @@
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
environment: "jsdom",
globals: true,
passWithNoTests: true,
include: ["tests/**/*.test.ts"]
}
});