diff --git a/src/app/service/sandbox/runtime.ts b/src/app/service/sandbox/runtime.ts index cc15f3ba5..8b1dc5c7b 100644 --- a/src/app/service/sandbox/runtime.ts +++ b/src/app/service/sandbox/runtime.ts @@ -18,7 +18,7 @@ import type { ValueUpdateData } from "../content/types"; import { getStorageName } from "@App/pkg/utils/utils"; import type { EmitEventRequest, ScriptLoadInfo } from "../service_worker/types"; import { CATRetryError } from "../content/exec_warp"; -import { getMetadataStr, getUserConfigStr } from "@App/pkg/utils/script"; +import { getMetadataStr, getUserConfigStr } from "@App/pkg/utils/utils"; export class Runtime { cronJob: Map> = new Map(); diff --git a/src/app/service/service_worker/runtime.ts b/src/app/service/service_worker/runtime.ts index 42312dbac..8432c5716 100644 --- a/src/app/service/service_worker/runtime.ts +++ b/src/app/service/service_worker/runtime.ts @@ -22,7 +22,7 @@ import { type SystemConfig } from "@App/pkg/config/config"; import { type ResourceService } from "./resource"; import { LocalStorageDAO } from "@App/app/repo/localStorage"; import Logger from "@App/app/logger/logger"; -import { getMetadataStr, getUserConfigStr } from "@App/pkg/utils/script"; +import { getMetadataStr, getUserConfigStr } from "@App/pkg/utils/utils"; import type { GMInfoEnv } from "../content/types"; export class RuntimeService { diff --git a/src/pkg/utils/script.test.ts b/src/pkg/utils/script.test.ts index b54c22797..aadeabfd9 100644 --- a/src/pkg/utils/script.test.ts +++ b/src/pkg/utils/script.test.ts @@ -1,5 +1,6 @@ import { describe, test, expect } from "vitest"; -import { parseMetadata, getMetadataStr, getUserConfigStr } from "./script"; +import { parseMetadata } from "./script" +import { getMetadataStr, getUserConfigStr } from "./utils"; import { parseUserConfig } from "./yaml" describe("parseMetadata", () => { diff --git a/src/pkg/utils/script.ts b/src/pkg/utils/script.ts index ffb6444ea..3decd7557 100644 --- a/src/pkg/utils/script.ts +++ b/src/pkg/utils/script.ts @@ -19,24 +19,6 @@ import { nextTime } from "./cron"; import type { InstallSource } from "@App/app/service/service_worker/types"; import { parseUserConfig } from "./yaml"; -export function getMetadataStr(code: string): string | null { - const start = code.indexOf("==UserScript=="); - const end = code.indexOf("==/UserScript=="); - if (start === -1 || end === -1) { - return null; - } - return `// ${code.substring(start, end + 15)}`; -} - -export function getUserConfigStr(code: string): string | null { - const start = code.indexOf("==UserConfig=="); - const end = code.indexOf("==/UserConfig=="); - if (start === -1 || end === -1) { - return null; - } - return `/* ${code.substring(start, end + 15)} */`; -} - export function parseMetadata(code: string): Metadata | null { let issub = false; let regex = /\/\/\s*==UserScript==([\s\S]+?)\/\/\s*==\/UserScript==/m; diff --git a/src/pkg/utils/utils.ts b/src/pkg/utils/utils.ts index 4d90f5045..8ca70be1b 100644 --- a/src/pkg/utils/utils.ts +++ b/src/pkg/utils/utils.ts @@ -235,4 +235,22 @@ export function strToBase64(str: string): string { }) ); } -*/ \ No newline at end of file +*/ + +export function getMetadataStr(code: string): string | null { + const start = code.indexOf("==UserScript=="); + const end = code.indexOf("==/UserScript=="); + if (start === -1 || end === -1) { + return null; + } + return `// ${code.substring(start, end + 15)}`; +} + +export function getUserConfigStr(code: string): string | null { + const start = code.indexOf("==UserConfig=="); + const end = code.indexOf("==/UserConfig=="); + if (start === -1 || end === -1) { + return null; + } + return `/* ${code.substring(start, end + 15)} */`; +}