Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: 脚本header悬停提示
  • Loading branch information
CodFrm committed Oct 27, 2021
1 parent 7175c6f commit a0eabad
Show file tree
Hide file tree
Showing 28 changed files with 79 additions and 63 deletions.
2 changes: 1 addition & 1 deletion 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"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "scriptcat",
"version": "0.7.1",
"version": "0.7.2",
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
"scripts": {
"test": "jest",
Expand Down
2 changes: 1 addition & 1 deletion 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/";

Expand Down
2 changes: 1 addition & 1 deletion 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";
Expand Down
2 changes: 1 addition & 1 deletion 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";
Expand Down
2 changes: 1 addition & 1 deletion 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;

Expand Down
2 changes: 1 addition & 1 deletion 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";
Expand Down
3 changes: 1 addition & 2 deletions 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";
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion 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";
Expand Down
2 changes: 1 addition & 1 deletion 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";
Expand Down
2 changes: 1 addition & 1 deletion src/apps/user/manager.ts
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/background.ts
Expand Up @@ -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";
Expand Down
18 changes: 2 additions & 16 deletions 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();

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions 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");

Expand Down
16 changes: 2 additions & 14 deletions 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";
Expand All @@ -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();

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion 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";

Expand Down
48 changes: 48 additions & 0 deletions 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);
});
}
});
}
3 changes: 1 addition & 2 deletions src/pkg/utils.ts → 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;
Expand Down Expand Up @@ -298,4 +297,4 @@ export class waitGroup {
this.callback();
}
}
}
}
2 changes: 1 addition & 1 deletion 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";
Expand Down
6 changes: 1 addition & 5 deletions src/types/tampermonkey.d.ts
Expand Up @@ -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<GM_Types.XHRResponse>;
}

declare namespace CAT_Types {
interface ProxyRule {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/views/components/ResizableEditor.vue
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/views/pages/Import/index.vue
Expand Up @@ -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({})
Expand Down
2 changes: 1 addition & 1 deletion 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,
Expand Down
2 changes: 1 addition & 1 deletion src/views/pages/Option/tabs/Logger.vue
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/views/pages/Option/tabs/ScriptList.vue
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/views/pages/Option/tabs/ScriptTab/index.vue
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/views/pages/Option/tabs/Tools.vue
Expand Up @@ -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";
Expand Down

0 comments on commit a0eabad

Please sign in to comment.