diff --git a/package.json b/package.json index a249be3..7f3abfc 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@dnd-kit/utilities": "^3.2.2", "@reduxjs/toolkit": "^2.3.0", "cron": "^3.2.1", + "crypto-js": "^4.2.0", "dayjs": "^1.11.13", "dexie": "^4.0.10", "eventemitter3": "^5.0.1", @@ -45,6 +46,7 @@ "@rspack/cli": "^1.0.14", "@rspack/core": "^1.0.14", "@types/chrome": "^0.0.279", + "@types/crypto-js": "^4.2.2", "@types/node": "^22.10.2", "@types/pako": "^2.0.3", "@types/react": "^18.2.48", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3e82191..5c0a860 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ importers: cron: specifier: ^3.2.1 version: 3.2.1 + crypto-js: + specifier: ^4.2.0 + version: 4.2.0 dayjs: specifier: ^1.11.13 version: 1.11.13 @@ -90,6 +93,9 @@ importers: '@types/chrome': specifier: ^0.0.279 version: 0.0.279 + '@types/crypto-js': + specifier: ^4.2.2 + version: 4.2.2 '@types/node': specifier: ^22.10.2 version: 22.10.2 @@ -1029,6 +1035,9 @@ packages: '@types/cookie@0.6.0': resolution: {integrity: sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==} + '@types/crypto-js@4.2.2': + resolution: {integrity: sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==} + '@types/eslint-scope@3.7.7': resolution: {integrity: sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==} @@ -1724,6 +1733,9 @@ packages: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} + crypto-js@4.2.0: + resolution: {integrity: sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==} + css-tree@3.0.1: resolution: {integrity: sha512-8Fxxv+tGhORlshCdCwnNJytvlvq46sOLSYEx2ZIGurahWvMucSRnyjPA3AmrMq4VPRYbHVpWj5VkiVasrM2H4Q==} engines: {node: ^10 || ^12.20.0 || ^14.13.0 || >=15.0.0} @@ -4603,6 +4615,8 @@ snapshots: '@types/cookie@0.6.0': {} + '@types/crypto-js@4.2.2': {} + '@types/eslint-scope@3.7.7': dependencies: '@types/eslint': 9.6.1 @@ -5607,6 +5621,8 @@ snapshots: shebang-command: 2.0.0 which: 2.0.2 + crypto-js@4.2.0: {} + css-tree@3.0.1: dependencies: mdn-data: 2.12.1 diff --git a/src/app/const.ts b/src/app/const.ts new file mode 100644 index 0000000..b40531e --- /dev/null +++ b/src/app/const.ts @@ -0,0 +1,14 @@ +import { version } from "../../package.json"; + +export const ExtVersion = version; + +export const ExtServer = "https://ext.scriptcat.org/"; + +export const ExternalWhitelist = [ + "greasyfork.org", + "scriptcat.org", + "tampermonkey.net.cn", + "openuserjs.org", +]; + +export const ExternalMessage = "externalMessage"; diff --git a/src/app/repo/repo.ts b/src/app/repo/repo.ts index 5b3cf42..d07c12e 100644 --- a/src/app/repo/repo.ts +++ b/src/app/repo/repo.ts @@ -1,5 +1,5 @@ export abstract class Repo { - constructor(private prefix: string) { + constructor(protected prefix: string) { if (!prefix.endsWith(":")) { this.prefix += ":"; } diff --git a/src/app/repo/resource.ts b/src/app/repo/resource.ts index 795d13e..e47f4a6 100644 --- a/src/app/repo/resource.ts +++ b/src/app/repo/resource.ts @@ -1,14 +1,15 @@ -import { DAO, db } from "./dao"; +import { Repo } from "./repo"; +import { v5 as uuidv5 } from "uuid"; export type ResourceType = "require" | "require-css" | "resource"; export interface Resource { - id: number; - url: string; + url: string; // key content: string; base64: string; hash: ResourceHash; type: ResourceType; + link: { [key: string]: boolean }; // 关联的脚本 contentType: string; createtime: number; updatetime?: number; @@ -22,11 +23,18 @@ export interface ResourceHash { sha512: string; } -export class ResourceDAO extends DAO { - public tableName = "resource"; +const ResourceNamespace = "76f45084-91b1-42c1-8be8-cbcc54b171f0"; +export class ResourceDAO extends Repo { constructor() { - super(); - this.table = db.table(this.tableName); + super("resource"); + } + + protected joinKey(key: string) { + return this.prefix + uuidv5(key, ResourceNamespace); + } + + save(resource: Resource) { + return super._save(resource.url, resource); } } diff --git a/src/app/repo/resource_link.ts b/src/app/repo/resource_link.ts deleted file mode 100644 index 3425a96..0000000 --- a/src/app/repo/resource_link.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { DAO, db } from "./dao"; - -export interface ResourceLink { - id: number; - url: string; - scriptId: number; - createtime?: number; -} - -export class ResourceLinkDAO extends DAO { - public tableName = "resourceLink"; - - constructor() { - super(); - this.table = db.table(this.tableName); - } -} diff --git a/src/app/repo/scripts.ts b/src/app/repo/scripts.ts index a63d6ab..1f6137c 100644 --- a/src/app/repo/scripts.ts +++ b/src/app/repo/scripts.ts @@ -41,10 +41,8 @@ export interface Config { export type UserConfig = { [key: string]: { [key: string]: Config } }; export interface Script { - // id: number; // 脚本id mv3迁移为chrome.storage后舍弃 uuid: string; // 脚本uuid,通过脚本uuid识别唯一脚本 name: string; // 脚本名称 - code: string; // 脚本执行代码 namespace: string; // 脚本命名空间 author?: string; // 脚本作者 originDomain?: string; // 脚本来源域名 @@ -67,13 +65,18 @@ export interface Script { nextruntime?: number; // 脚本下一次运行时间戳 } +// 分开存储脚本代码 +export interface ScriptCode { + uuid: string; + code: string; // 脚本执行代码 +} + // 脚本运行时的资源,包含已经编译好的脚本与脚本需要的资源 export interface ScriptRunResouce extends Script { - grantMap: { [key: string]: string }; + code: string; value: { [key: string]: Value }; flag: string; resource: { [key: string]: Resource }; - sourceCode: string; } export class ScriptDAO extends Repo