diff --git a/build/scriptcat/manifest.json b/build/scriptcat/manifest.json index 028af09c..b30873b9 100644 --- a/build/scriptcat/manifest.json +++ b/build/scriptcat/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "ScriptCat", - "version": "0.7.1", + "version": "0.7.2", "description": "脚本猫,一个用户脚本的框架,可编写脚本每天帮你自动处理事务.", "background": { "page": "background.html" diff --git a/package-lock.json b/package-lock.json index aa8b4e70..debd9418 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "scriptcat", - "version": "0.7.0", + "version": "0.7.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "scriptcat", - "version": "0.7.0", + "version": "0.7.2", "license": "MIT", "dependencies": { "adm-zip": "^0.5.3", diff --git a/package.json b/package.json index b3b19d1c..31a45504 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scriptcat", - "version": "0.7.1", + "version": "0.7.2", "description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!", "scripts": { "test": "jest", diff --git a/src/apps/config.ts b/src/apps/config.ts index 11413b65..875ae979 100644 --- a/src/apps/config.ts +++ b/src/apps/config.ts @@ -1,4 +1,4 @@ -export const ExtVersion = "0.7.1"; +export const ExtVersion = "0.7.2"; export const Server = process.env.NODE_ENV == "production" ? "https://sc.icodef.com/" : "http://localhost:8080/"; diff --git a/src/apps/grant/background.ts b/src/apps/grant/background.ts index cb94b0db..ac0222d9 100644 --- a/src/apps/grant/background.ts +++ b/src/apps/grant/background.ts @@ -1,5 +1,5 @@ import { PermissionModel } from "@App/model/permission"; -import { isFirefox } from "@App/pkg/utils"; +import { isFirefox } from "@App/pkg/utils/utils"; import { App } from "../app"; import { AppEvent, ListenGmLog, PermissionConfirm, ScriptGrant, ScriptValueChange, TabMenuClick, TabRemove } from "../msg-center/event"; import { MsgCenter } from "../msg-center/msg-center"; diff --git a/src/apps/grant/frontend.ts b/src/apps/grant/frontend.ts index eaf49b17..feee0c74 100644 --- a/src/apps/grant/frontend.ts +++ b/src/apps/grant/frontend.ts @@ -1,7 +1,7 @@ import { ScriptCache } from "@App/model/do/script"; import { Value } from "@App/model/do/value"; import { addStyle } from "@App/pkg/frontend"; -import { randomInt, randomString } from "@App/pkg/utils"; +import { randomInt, randomString } from "@App/pkg/utils/utils"; import { BrowserMsg } from "../msg-center/browser"; import { AppEvent, ScriptValueChange } from "../msg-center/event"; import { Grant } from "./interface"; diff --git a/src/apps/msg-center/browser.ts b/src/apps/msg-center/browser.ts index 771095e7..f1a28927 100644 --- a/src/apps/msg-center/browser.ts +++ b/src/apps/msg-center/browser.ts @@ -1,7 +1,7 @@ // 前端用通信 -import { randomString } from "@App/pkg/utils"; +import { randomString } from "@App/pkg/utils/utils"; export type ListenMsg = (msg: any) => void; diff --git a/src/apps/resource.ts b/src/apps/resource.ts index 62296fba..f70d27d1 100644 --- a/src/apps/resource.ts +++ b/src/apps/resource.ts @@ -1,6 +1,6 @@ import { Resource } from "@App/model/do/resource"; import { ResourceLinkModel, ResourceModel } from "@App/model/resource"; -import { blobToBase64, strToBase64 } from "@App/pkg/utils"; +import { blobToBase64, strToBase64 } from "@App/pkg/utils/utils"; import axios from "axios"; import crypto from "crypto-js"; import { App } from "./app"; diff --git a/src/apps/script/controller.ts b/src/apps/script/controller.ts index 5810042d..6271bb68 100644 --- a/src/apps/script/controller.ts +++ b/src/apps/script/controller.ts @@ -1,7 +1,7 @@ import { v5 as uuidv5 } from 'uuid'; import { SCRIPT_STATUS_ENABLE, SCRIPT_STATUS_DISABLE, Script, SCRIPT_RUN_STATUS_COMPLETE, SCRIPT_TYPE_BACKGROUND, SCRIPT_TYPE_CRONTAB, SCRIPT_TYPE_NORMAL, ScriptCache } from "@App/model/do/script"; import { ScriptModel } from "@App/model/script"; -import { get, Page, randomString } from "@App/pkg/utils"; +import { get, Page, randomString } from "@App/pkg/utils/utils"; import { ScriptExec, ScriptStatusChange, ScriptStop, ScriptUninstall, ScriptReinstall, ScriptInstall, RequestInstallInfo, ScriptCheckUpdate, RequestConfirmInfo, SubscribeUpdate, Unsubscribe, SubscribeCheckUpdate, ImportFile, OpenImportFileWindow, RequestImportFile, ScriptValueChange } from "../msg-center/event"; import { MsgCenter } from "../msg-center/msg-center"; import { parseMetadata, parseUserConfig, copyScript, copySubscribe } from "./utils"; @@ -264,7 +264,6 @@ export class ScriptController { updatetime: new Date().getTime(), checktime: 0, }; - console.log(script); let old = await this.scriptModel.findByUUID(script.uuid); if (!old && uuid == undefined) { old = await this.scriptModel.findByNameAndNamespace(script.name, script.namespace); diff --git a/src/apps/script/manager.ts b/src/apps/script/manager.ts index d4551d35..aac9ae2f 100644 --- a/src/apps/script/manager.ts +++ b/src/apps/script/manager.ts @@ -1,7 +1,7 @@ import axios from "axios"; import { MsgCenter } from "@App/apps/msg-center/msg-center"; import { AppEvent, ScriptExec, ScriptRunStatusChange, ScriptStatusChange, ScriptStop, ScriptUninstall, ScriptReinstall, ScriptValueChange, TabRemove, RequestTabRunScript, ScriptInstall, RequestInstallInfo, ScriptCheckUpdate, RequestConfirmInfo, ListenGmLog, SubscribeUpdate, Unsubscribe, SubscribeCheckUpdate, ImportFile, OpenImportFileWindow, RequestImportFile, ScriptInstallByURL } from "@App/apps/msg-center/event"; -import { dealScript, get, randomString } from "@App/pkg/utils"; +import { dealScript, get, randomString } from "@App/pkg/utils/utils"; import { App } from "../app"; import { UrlMatch } from "@App/pkg/match"; import { ValueModel } from "@App/model/value"; diff --git a/src/apps/user/controller.ts b/src/apps/user/controller.ts index cc6304b5..47fcb913 100644 --- a/src/apps/user/controller.ts +++ b/src/apps/user/controller.ts @@ -1,4 +1,4 @@ -import { get } from "@App/pkg/utils"; +import { get } from "@App/pkg/utils/utils"; import { Server } from "../config"; import { TriggerSync, UserLogin, UserLogout } from "../msg-center/event"; import { MsgCenter } from "../msg-center/msg-center"; diff --git a/src/apps/user/manager.ts b/src/apps/user/manager.ts index 5910a934..40459fa1 100644 --- a/src/apps/user/manager.ts +++ b/src/apps/user/manager.ts @@ -4,7 +4,7 @@ import { SubscribeModel } from "@App/model/subscribe"; import { SyncModel } from "@App/model/sync"; import { ValueModel } from "@App/model/value"; import { SystemConfig } from "@App/pkg/config"; -import { get, getJson, InfoNotification, postJson, put, putJson } from "@App/pkg/utils"; +import { get, getJson, InfoNotification, postJson, put, putJson } from "@App/pkg/utils/utils"; import { KeyCode } from "monaco-editor"; import { App } from "../app"; import { Server } from "../config"; diff --git a/src/background.ts b/src/background.ts index 16a610c8..661a3a32 100644 --- a/src/background.ts +++ b/src/background.ts @@ -9,7 +9,7 @@ import { DBLogger } from "./apps/logger/logger"; import { migrate } from "./model/migrate"; import { SCRIPT_STATUS_ENABLE, Script, SCRIPT_TYPE_NORMAL, SCRIPT_STATUS_DISABLE } from "./model/do/script"; import { MapCache } from "./pkg/storage/cache/cache"; -import { get } from "./pkg/utils"; +import { get } from "./pkg/utils/utils"; import { Server } from "./apps/config"; import { Subscribe, SUBSCRIBE_STATUS_ENABLE } from "./model/do/subscribe"; import { UserManager } from "./apps/user/manager"; diff --git a/src/install.ts b/src/install.ts index 63c5ed80..c60e133d 100644 --- a/src/install.ts +++ b/src/install.ts @@ -1,19 +1,15 @@ import "reflect-metadata"; import "vuetify/dist/vuetify.min.css"; import Vue from "vue"; -import { languages } from "monaco-editor"; import Vuetify from "vuetify"; - - import App from "@App/views/pages/Install/index.vue"; -// @ts-ignore -import dts from "@App/types/tampermonkey.d.ts"; import { migrate } from "./model/migrate"; import { ENV_FRONTEND, InitApp } from "./apps/app"; import { DBLogger } from "./apps/logger/logger"; import { SystemCache } from "./pkg/storage/cache/system-cache"; +import { registerEditorPrompt } from "./pkg/utils/editor"; migrate(); @@ -28,17 +24,7 @@ Vue.use(Vuetify); const opts = {}; const vuetifyInstance = new Vuetify(opts); -// @ts-ignore -self.MonacoEnvironment = { - getWorkerUrl: function (moduleId: any, label: any) { - if (label === "typescript" || label === "javascript") { - return "./src/ts.worker.js"; - } - return "./src/editor.worker.js"; - }, -}; - -languages.typescript.javascriptDefaults.addExtraLib(dts, "tampermonkey.d.ts"); +registerEditorPrompt(); new Vue({ vuetify: vuetifyInstance, diff --git a/src/model/model.ts b/src/model/model.ts index a020bf79..dd813ff0 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -1,5 +1,5 @@ -import Dexie, { PromiseExtended } from "dexie"; -import { Page } from "../pkg/utils"; +import Dexie from "dexie"; +import { Page } from "../pkg/utils/utils"; export let db = new Dexie("ScriptCat"); diff --git a/src/options.tsx b/src/options.tsx index 051763b8..053b824e 100644 --- a/src/options.tsx +++ b/src/options.tsx @@ -1,9 +1,6 @@ import "reflect-metadata"; import "vuetify/dist/vuetify.min.css"; -// @ts-ignore -import dts from "@App/types/tampermonkey.d.ts"; -import { languages } from "monaco-editor"; import Vue from "vue"; import Component from "vue-class-component"; import VueRouter, { RouteConfig } from "vue-router"; @@ -17,6 +14,7 @@ import { DBLogger } from "./apps/logger/logger"; import { MapCache } from "./pkg/storage/cache/cache"; import { ENV_FRONTEND, InitApp } from "./apps/app"; import { SystemConfig } from "./pkg/config"; +import { registerEditorPrompt } from "./pkg/utils/editor"; migrate(); @@ -28,17 +26,7 @@ InitApp({ SystemConfig.init(); -// @ts-ignore -self.MonacoEnvironment = { - getWorkerUrl: function (moduleId: any, label: any) { - if (label === "typescript" || label === "javascript") { - return "./src/ts.worker.js"; - } - return "./src/editor.worker.js"; - }, -}; - -languages.typescript.javascriptDefaults.addExtraLib(dts, "tampermonkey.d.ts"); +registerEditorPrompt(); Vue.use(VuetifyDialogPromise); Vue.use(VueRouter); diff --git a/src/pkg/storage/cache/system-cache.ts b/src/pkg/storage/cache/system-cache.ts index 00047ebf..da6b3cae 100644 --- a/src/pkg/storage/cache/system-cache.ts +++ b/src/pkg/storage/cache/system-cache.ts @@ -1,6 +1,6 @@ import { SystemCacheEvent } from "@App/apps/msg-center/event"; import { MsgCenter } from "@App/apps/msg-center/msg-center"; -import { randomString } from "@App/pkg/utils"; +import { randomString } from "@App/pkg/utils/utils"; import { CHANGE_EVENT } from "../storage"; import { MapCache, ICache } from "./cache"; diff --git a/src/pkg/utils/editor.ts b/src/pkg/utils/editor.ts new file mode 100644 index 00000000..1f763057 --- /dev/null +++ b/src/pkg/utils/editor.ts @@ -0,0 +1,48 @@ +//@ts-ignore +import dts from "@App/types/tampermonkey.d.ts"; +import { CancellationToken, editor, languages, Position } from "monaco-editor"; + +export function registerEditorPrompt() { + // @ts-ignore + self.MonacoEnvironment = { + getWorkerUrl: function (moduleId: any, label: any) { + if (label === "typescript" || label === "javascript") { + return "./src/ts.worker.js"; + } + return "./src/editor.worker.js"; + }, + }; + + languages.typescript.javascriptDefaults.addExtraLib(dts, "tampermonkey.d.ts"); + + // 悬停提示 + const prompt: { [key: string]: any } = { + 'name': '脚本名称', + 'description': '脚本描述', + 'namespace': '脚本命名空间', + 'version': '脚本版本', + 'author': '脚本作者', + 'background': '后台脚本', + }; + + languages.registerHoverProvider('javascript', { + provideHover: (model, position, token) => { + return new Promise(resolve => { + const line = model.getLineContent(position.lineNumber); + let flag = /^\/\/\s*@(\w+?)(\s+(.*?)|)$/.exec(line); + if (flag) { + return resolve({ + contents: [{ value: prompt[flag[1]] }] + }); + } + // 匹配==UserScript== + if (/==UserScript==/.test(line)) { + return resolve({ + contents: [{ value: '一个用户脚本' }], + }); + } + return resolve(null); + }); + } + }); +} diff --git a/src/pkg/utils.ts b/src/pkg/utils/utils.ts similarity index 99% rename from src/pkg/utils.ts rename to src/pkg/utils/utils.ts index f7970dfe..c35a6932 100644 --- a/src/pkg/utils.ts +++ b/src/pkg/utils/utils.ts @@ -1,7 +1,6 @@ import { App } from "@App/apps/app"; import { Logger } from "@App/apps/msg-center/event"; import { LOGGER_LEVEL } from "@App/model/do/logger"; - export class Page { protected _page: number; protected _count: number; @@ -298,4 +297,4 @@ export class waitGroup { this.callback(); } } -} \ No newline at end of file +} diff --git a/src/sandbox.ts b/src/sandbox.ts index 0b4d829a..1009a3aa 100644 --- a/src/sandbox.ts +++ b/src/sandbox.ts @@ -1,7 +1,7 @@ import { CronJob } from "cron"; import { buildThis, compileScript, createSandboxContext } from "@App/pkg/sandbox"; import { SandboxContext } from "./apps/grant/frontend"; -import { SendLogger } from "./pkg/utils"; +import { SendLogger } from "./pkg/utils/utils"; import { App, ENV_FRONTEND, InitApp } from "./apps/app"; import { MapCache } from "./pkg/storage/cache/cache"; import { ConsoleLogger } from "./apps/logger/logger"; diff --git a/src/types/tampermonkey.d.ts b/src/types/tampermonkey.d.ts index e7fd2a40..1a02ec60 100644 --- a/src/types/tampermonkey.d.ts +++ b/src/types/tampermonkey.d.ts @@ -110,10 +110,6 @@ declare function GM_getCookieStore(tabid: number, ondone: (storeId: number, erro declare function CAT_setProxy(rule: CAT_Types.ProxyRule[] | string): void; declare function CAT_clearProxy(): void; declare function CAT_click(x: number, y: number): void; -// 同步函数 -declare namespace GM { - declare function fetch(details: GM_Types.XHRDetails): Promise; -} declare namespace CAT_Types { interface ProxyRule { @@ -197,7 +193,7 @@ declare namespace GM_Types { method?: "GET" | "HEAD" | "POST" | "PUT" | "DELETE" url: string headers?: { [key: string]: string } - data?: string + data?: any cookie?: string binary?: boolean timeout?: number diff --git a/src/views/components/ResizableEditor.vue b/src/views/components/ResizableEditor.vue index e41cfd8d..75a9f570 100644 --- a/src/views/components/ResizableEditor.vue +++ b/src/views/components/ResizableEditor.vue @@ -25,7 +25,7 @@ import { Component, Prop, Vue } from "vue-property-decorator"; import { editor } from "monaco-editor"; -import { sleep } from "@App/pkg/utils"; +import { sleep } from "@App/pkg/utils/utils"; import normalTpl from "@App/template/normal.tpl"; import crontabTpl from "@App/template/crontab.tpl"; import backgroundTpl from "@App/template/background.tpl"; diff --git a/src/views/pages/Import/index.vue b/src/views/pages/Import/index.vue index 4425b0bd..c4222238 100644 --- a/src/views/pages/Import/index.vue +++ b/src/views/pages/Import/index.vue @@ -197,7 +197,7 @@ import { SCRIPT_STATUS_ENABLE, } from "@App/model/do/script"; import { SUBSCRIBE_STATUS_ENABLE } from "@App/model/do/subscribe"; -import { base64ToStr, waitGroup } from "@App/pkg/utils"; +import { base64ToStr, waitGroup } from "@App/pkg/utils/utils"; import { Component, Vue } from "vue-property-decorator"; @Component({}) diff --git a/src/views/pages/Option/store/user.ts b/src/views/pages/Option/store/user.ts index abedc925..4f47a97b 100644 --- a/src/views/pages/Option/store/user.ts +++ b/src/views/pages/Option/store/user.ts @@ -1,5 +1,5 @@ import { Server } from "@App/apps/config"; -import { get } from "@App/pkg/utils"; +import { get } from "@App/pkg/utils/utils"; import { Action, Module, diff --git a/src/views/pages/Option/tabs/Logger.vue b/src/views/pages/Option/tabs/Logger.vue index 60c7ea93..74e20a77 100644 --- a/src/views/pages/Option/tabs/Logger.vue +++ b/src/views/pages/Option/tabs/Logger.vue @@ -57,7 +57,7 @@ import { LOGGER_LEVEL_INFO, LOGGER_LEVEL_WARN, } from "@App/model/do/logger"; -import { Page } from "@App/pkg/utils"; +import { Page } from "@App/pkg/utils/utils"; import { Vue, Component, Watch } from "vue-property-decorator"; import dayjs from "dayjs"; diff --git a/src/views/pages/Option/tabs/ScriptList.vue b/src/views/pages/Option/tabs/ScriptList.vue index de373185..1317cf80 100644 --- a/src/views/pages/Option/tabs/ScriptList.vue +++ b/src/views/pages/Option/tabs/ScriptList.vue @@ -600,7 +600,7 @@ import { } from "@App/apps/msg-center/event"; import eventBus from "@App/views/EventBus"; -import { Page } from "@App/pkg/utils"; +import { Page } from "@App/pkg/utils/utils"; import { nextTime } from "@App/views/pages/utils"; import { ValueModel } from "@App/model/value"; import { Value } from "@App/model/do/value"; diff --git a/src/views/pages/Option/tabs/ScriptTab/index.vue b/src/views/pages/Option/tabs/ScriptTab/index.vue index c01dfee7..7087e0b7 100644 --- a/src/views/pages/Option/tabs/ScriptTab/index.vue +++ b/src/views/pages/Option/tabs/ScriptTab/index.vue @@ -56,7 +56,7 @@ import META from "./META.vue"; import Editor from "./Editor.vue"; import Resource from "./Resource.vue"; import Storage from "./Storage.vue"; -import { get } from "@App/pkg/utils"; +import { get } from "@App/pkg/utils/utils"; import EventType from "../../EventType"; import { languages } from "monaco-editor"; import { scriptModule } from "../../store/script"; diff --git a/src/views/pages/Option/tabs/Tools.vue b/src/views/pages/Option/tabs/Tools.vue index 9b58e6bc..5af39285 100644 --- a/src/views/pages/Option/tabs/Tools.vue +++ b/src/views/pages/Option/tabs/Tools.vue @@ -20,7 +20,7 @@ import Panels, { import { saveAs } from "file-saver"; import { File, Resource, Script, Subscribe } from "@App/model/do/back"; import { SCRIPT_STATUS_ENABLE } from "@App/model/do/script"; -import { strToBase64 } from "@App/pkg/utils"; +import { strToBase64 } from "@App/pkg/utils/utils"; import { SUBSCRIBE_STATUS_ENABLE } from "@App/model/do/subscribe"; import { ToolsController } from "@App/apps/tools/controller"; import { SystemConfig } from "@App/pkg/config";