-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
728 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// ==UserScript== | ||
// @name userconfig | ||
// @namespace https://bbs.tampermonkey.net.cn/ | ||
// @version 0.1.0 | ||
// @description 会在页面上显示用户配置,可以可视化的进行配置 | ||
// @author You | ||
// @background | ||
// @grant GM_getValue | ||
// ==/UserScript== | ||
|
||
/* ==UserConfig== | ||
group1: | ||
configA: # 键值为group.config,例如本键为:group1.configA | ||
title: 配置A # 配置的标题 | ||
description: 这是一个文本类型的配置 # 配置的描述内容 | ||
type: text # 选项类型,如果不填写会根据数据自动识别 | ||
default: 默认值 # 配置的默认值 | ||
min: 2 # 文本最短2个字符 | ||
max: 18 # 文本最长18个字符 | ||
password: true # 设置为密码 | ||
configB: | ||
title: 配置B | ||
description: 这是一个选择框的配置 | ||
type: checkbox | ||
default: true | ||
configC: | ||
title: 配置C | ||
description: 这是一个列表选择的配置 | ||
type: select | ||
default: 1 | ||
values: [1,2,3,4,5] | ||
configD: | ||
title: 配置D | ||
description: 这是一个动态列表选择的配置 | ||
type: select | ||
bind: $cookies # 动态显示绑定的values,值是以$开头的key,value需要是一个数组 | ||
configE: | ||
title: 配置E | ||
description: 这是一个多选列表的配置 | ||
type: mult-select | ||
default: [1] | ||
values: [1,2,3,4,5] | ||
configF: | ||
title: 配置F | ||
description: 这是一个动态多选列表的配置 | ||
type: mult-select | ||
bind: $cookies | ||
configG: | ||
title: 配置G | ||
description: 这是一个数字的配置 | ||
type: number | ||
default: 1 | ||
min: 10 # 最小值 | ||
max: 16 # 最大值 | ||
unit: 分 # 表示单位 | ||
--- | ||
group2: | ||
configX: | ||
title: 配置A | ||
description: 这是一个文本类型的配置 | ||
default: 默认值 | ||
type: text | ||
==/UserConfig== */ | ||
|
||
setInterval(() => { | ||
console.log(GM_getValue("group1.configA")); | ||
}, 5000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import LoggerCore from "../logger/core"; | ||
import Logger from "../logger/logger"; | ||
import MessageInternal from "../message/internal"; | ||
|
||
export type Handler = (data: any) => void | Promise<any>; | ||
|
||
export default abstract class Controller { | ||
message: MessageInternal; | ||
|
||
name: string; | ||
|
||
logger: Logger; | ||
|
||
constructor(message: MessageInternal, name: string) { | ||
this.message = message; | ||
this.name = name; | ||
this.logger = LoggerCore.getLogger({ | ||
component: this.name, | ||
controller: true, | ||
}); | ||
} | ||
|
||
public dispatchEvent(event: string, data: any): Promise<any> { | ||
return this.message.syncSend(`${this.name}-${event}`, data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
import { MessageHander } from "../message/message"; | ||
import LoggerCore from "../logger/core"; | ||
import Logger from "../logger/logger"; | ||
import { MessageHander, MessageSender } from "../message/message"; | ||
|
||
export type Handler = (data: any) => void | Promise<any>; | ||
export type Handler = (data: any, sender: MessageSender) => void | Promise<any>; | ||
|
||
export default class Manager { | ||
export default abstract class Manager { | ||
message: MessageHander; | ||
|
||
constructor(message: MessageHander) { | ||
name: string; | ||
|
||
logger: Logger; | ||
|
||
constructor(message: MessageHander, name: string) { | ||
this.message = message; | ||
this.name = name; | ||
this.logger = LoggerCore.getLogger({ component: this.name, manager: true }); | ||
} | ||
|
||
public listenEvent(action: string, func: Handler) { | ||
this.message.setHandler(action, (_action: string, data: any) => { | ||
return new Promise((resolve) => { | ||
resolve(func(data)); | ||
}); | ||
}); | ||
this.message.setHandler( | ||
`${this.name}-${action}`, | ||
(_action: string, data: any, sender: MessageSender) => { | ||
return new Promise((resolve) => { | ||
resolve(func(data, sender)); | ||
}); | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import IoC from "@App/app/ioc"; | ||
import MessageInternal from "@App/app/message/internal"; | ||
import Controller from "../controller"; | ||
|
||
@IoC.Singleton(MessageInternal) | ||
export default class ValueController extends Controller { | ||
internal: MessageInternal; | ||
|
||
constructor(internal: MessageInternal) { | ||
super(internal, "value"); | ||
this.internal = internal; | ||
} | ||
|
||
public setValue(scriptId: number, key: string, value: any) { | ||
return this.dispatchEvent("upsert", { | ||
scriptId, | ||
key, | ||
value, | ||
}); | ||
} | ||
} |
Oops, something went wrong.