mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-12-19 18:25:44 +08:00
完善执行命令功能 90%
This commit is contained in:
@@ -2,6 +2,50 @@
|
||||
* 所有的匹配类型
|
||||
*/
|
||||
|
||||
const jsonSample = [
|
||||
"关键词",
|
||||
{
|
||||
"type": "img",
|
||||
"label": "图片匹配"
|
||||
},
|
||||
{
|
||||
"type": "files",
|
||||
"label": "文件匹配",
|
||||
"fileType": "file",
|
||||
"match": "/aaa/",
|
||||
"minLength": 1,
|
||||
"maxLength": 99
|
||||
},
|
||||
{
|
||||
"type": "regex",
|
||||
"label": "文本正则匹配",
|
||||
"match": "/bbb/i",
|
||||
"minLength": 1,
|
||||
"maxLength": 99
|
||||
},
|
||||
{
|
||||
"type": "over",
|
||||
"label": "无匹配时",
|
||||
"exclude": "/ccc/i",
|
||||
"minLength": 1,
|
||||
"maxLength": 99
|
||||
},
|
||||
{
|
||||
"type": "window",
|
||||
"label": "窗口动作",
|
||||
"match": {
|
||||
"app": [
|
||||
"ddd.app",
|
||||
"eee.exe"
|
||||
],
|
||||
"title": "/fff/",
|
||||
"class": [
|
||||
"ggg"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
const commandTypes = {
|
||||
key: {
|
||||
name: "key",
|
||||
@@ -10,9 +54,9 @@ const commandTypes = {
|
||||
matchLabel: "关键词",
|
||||
desc: "在主输入框输入对应关键字进入插件,最通用的一种模式,关键字可以设置多个",
|
||||
valueType: "array",
|
||||
disabledSpecialVars: /{{input}}|{{SelectFile}}|{{pwd}}|{{WindowInfo}}|{{MatchedFiles}}/g,
|
||||
disabledSpecialVars: /{{input}}|{{SelectFile}}|{{pwd}}|{{WindowInfo.*?}}|{{MatchedFiles.*?}}/g,
|
||||
matchToCmds: (rules, desc) => rules,
|
||||
verify: (rules) => rules.length > 0 || "关键词不能为空",
|
||||
verify: (rules) => !_.isEmpty(rules) || "关键词不能为空",
|
||||
},
|
||||
regex: {
|
||||
name: "regex",
|
||||
@@ -21,7 +65,7 @@ const commandTypes = {
|
||||
icon: "rule",
|
||||
desc: "匹配主输入框或超级面板选中的文本,可以获取输入框文本或选中文本作为变量",
|
||||
valueType: "regex",
|
||||
disabledSpecialVars: /{{SelectFile}}|{{WindowInfo}}|{{pwd}}|{{MatchedFiles}}/g,
|
||||
disabledSpecialVars: /{{SelectFile}}|{{WindowInfo.*?}}|{{pwd}}|{{MatchedFiles.*?}}/g,
|
||||
matchToCmds: (rules, desc) => [{
|
||||
label: desc,
|
||||
type: "regex",
|
||||
@@ -37,7 +81,7 @@ const commandTypes = {
|
||||
icon: "emergency",
|
||||
desc: "匹配主输入框的所有文本,但只有在该文本未设置对应的插件或功能时才生效",
|
||||
valueType: null,
|
||||
disabledSpecialVars: /{{SelectFile}}|{{WindowInfo}}|{{pwd}}|{{MatchedFiles}}/g,
|
||||
disabledSpecialVars: /{{SelectFile}}|{{WindowInfo.*?}}|{{pwd}}|{{MatchedFiles.*?}}/g,
|
||||
matchToCmds: (rules, desc) => [{
|
||||
label: desc,
|
||||
type: "over",
|
||||
@@ -52,7 +96,7 @@ const commandTypes = {
|
||||
icon: "widgets",
|
||||
desc: "匹配呼出uTools前或唤出超级面板时的活动窗口,可以获取窗口的信息或文件夹路径作为变量",
|
||||
valueType: "array",
|
||||
disabledSpecialVars: /{{input}}|{{MatchedFiles}}/g,
|
||||
disabledSpecialVars: /{{input}}|{{MatchedFiles.*?}}/g,
|
||||
matchToCmds: (rules, desc) => [{
|
||||
type: "window",
|
||||
label: desc,
|
||||
@@ -60,7 +104,7 @@ const commandTypes = {
|
||||
"app": rules
|
||||
}
|
||||
}],
|
||||
verify: rules => rules.length > 0 || "进程名不能为空"
|
||||
verify: rules => !_.isEmpty(rules) || "进程名不能为空"
|
||||
},
|
||||
img: {
|
||||
name: "img",
|
||||
@@ -69,7 +113,7 @@ const commandTypes = {
|
||||
icon: "panorama",
|
||||
desc: "匹配主输入框或超级面板选中的图片,并返回图片的 base64",
|
||||
valueType: null,
|
||||
disabledSpecialVars: /{{input}}|{{SelectFile}}|{{pwd}}|{{WindowInfo}}|{{MatchedFiles}}/g,
|
||||
disabledSpecialVars: /{{input}}|{{SelectFile}}|{{pwd}}|{{WindowInfo.*?}}|{{MatchedFiles.*?}}/g,
|
||||
matchToCmds: (rules, desc) => [{
|
||||
label: desc,
|
||||
type: "img",
|
||||
@@ -83,7 +127,7 @@ const commandTypes = {
|
||||
icon: "description",
|
||||
desc: "匹配主输入框或超级面板选中的文件,可以获取复制及选中的文件信息作为变量",
|
||||
valueType: "regex",
|
||||
disabledSpecialVars: /{{input}}|{{SelectFile}}|{{pwd}}|{{WindowInfo}}/g,
|
||||
disabledSpecialVars: /{{input}}|{{SelectFile}}|{{pwd}}|{{WindowInfo.*?}}/g,
|
||||
matchToCmds: (rules, desc) => [{
|
||||
type: "files",
|
||||
label: desc,
|
||||
@@ -110,50 +154,8 @@ const commandTypes = {
|
||||
return "专业模式json配置错误"
|
||||
}
|
||||
},
|
||||
jsonSample: [
|
||||
"关键词",
|
||||
{
|
||||
"type": "img",
|
||||
"label": "图片匹配"
|
||||
},
|
||||
{
|
||||
"type": "files",
|
||||
"label": "文件匹配",
|
||||
"fileType": "file",
|
||||
"match": "/aaa/",
|
||||
"minLength": 1,
|
||||
"maxLength": 99
|
||||
},
|
||||
{
|
||||
"type": "regex",
|
||||
"label": "文本正则匹配",
|
||||
"match": "/bbb/i",
|
||||
"minLength": 1,
|
||||
"maxLength": 99
|
||||
},
|
||||
{
|
||||
"type": "over",
|
||||
"label": "无匹配时",
|
||||
"exclude": "/ccc/i",
|
||||
"minLength": 1,
|
||||
"maxLength": 99
|
||||
},
|
||||
{
|
||||
"type": "window",
|
||||
"label": "窗口动作",
|
||||
"match": {
|
||||
"app": [
|
||||
"ddd.app",
|
||||
"eee.exe"
|
||||
],
|
||||
"title": "/fff/",
|
||||
"class": [
|
||||
"ggg"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
jsonSample: jsonSample
|
||||
}
|
||||
}
|
||||
|
||||
export default commandTypes
|
||||
export default commandTypes
|
||||
@@ -2,65 +2,126 @@
|
||||
* 所有的特殊变量
|
||||
*/
|
||||
|
||||
let escapeItem = item => {
|
||||
if (typeof item === 'number') return item
|
||||
item = typeof item === 'object' ? JSON.stringify(item) : item.replace('\\', '\\\\')
|
||||
return item.replace('$', '$$$')
|
||||
}
|
||||
|
||||
let parseTheFirstLayerOfObjects = obj => {
|
||||
let matched = /{{(\w+)(\[(\d+)\]){0,1}\.(\w+)}}/.exec(obj);
|
||||
return matched ? {
|
||||
obj: matched[1],
|
||||
index: matched[3],
|
||||
prop: matched[4],
|
||||
} : {};
|
||||
}
|
||||
|
||||
let handlingJsonVar = (jsonVar, srcObj) => {
|
||||
try {
|
||||
let parsed = parseTheFirstLayerOfObjects(jsonVar);
|
||||
if (!parsed.obj) return escapeItem(srcObj)
|
||||
else if (!parsed.index) return escapeItem(srcObj[parsed.prop])
|
||||
else return escapeItem(srcObj[parsed.index][parsed.prop])
|
||||
} catch {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
const specialVars = {
|
||||
isWin: {
|
||||
name: "isWin",
|
||||
label: "{{isWin}}",
|
||||
desc: "是否为 windows 系统,返回 0 或 1",
|
||||
disabledType: [],
|
||||
match: /{{isWin}}/mg,
|
||||
repl: () => utools.isWindows() ? 1 : 0
|
||||
},
|
||||
LocalId: {
|
||||
name: "LocalId",
|
||||
label: "{{LocalId}}",
|
||||
desc: "本机唯一ID"
|
||||
desc: "本机唯一ID",
|
||||
disabledType: [],
|
||||
match: /{{LocalId}}/mg,
|
||||
repl: () => utools.getNativeId()
|
||||
},
|
||||
BrowserUrl: {
|
||||
name: "BrowserUrl",
|
||||
label: "{{BrowserUrl}}",
|
||||
desc: "浏览器当前链接"
|
||||
disabledType: [],
|
||||
desc: "浏览器当前链接",
|
||||
match: /{{BrowserUrl}}/mg,
|
||||
repl: () => utools.getCurrentBrowserUrl()
|
||||
},
|
||||
ClipText: {
|
||||
name: "ClipText",
|
||||
label: "{{ClipText}}",
|
||||
desc: "剪贴板内容"
|
||||
disabledType: [],
|
||||
desc: "剪贴板内容",
|
||||
match: /{{ClipText}}/mg,
|
||||
repl: () => window.clipboardReadText()
|
||||
},
|
||||
subinput: {
|
||||
name: "subinput",
|
||||
label: "{{subinput}}",
|
||||
desc: "子输入框的文本"
|
||||
disabledType: [],
|
||||
tooltip: `可以自定义占位符,如{{subinput:请输入}}`,
|
||||
desc: "子输入框的文本",
|
||||
match: /{{subinput(:.+?){0,1}}}/mg,
|
||||
},
|
||||
input: {
|
||||
name: "input",
|
||||
label: "{{input}}",
|
||||
desc: "主输入框的文本"
|
||||
desc: "主输入框的文本",
|
||||
match: /{{input}}/mg,
|
||||
repl: () => quickcommand.enterData.payload
|
||||
},
|
||||
pwd: {
|
||||
name: "pwd",
|
||||
label: "{{pwd}}",
|
||||
desc: "文件管理器当前目录"
|
||||
desc: "文件管理器当前目录",
|
||||
match: /{{pwd}}/mg,
|
||||
repl: () => window.getCurrentFolderPathFix()
|
||||
},
|
||||
WindowInfo: {
|
||||
name: "WindowInfo",
|
||||
label: "{{WindowInfo}}",
|
||||
desc: "当前窗口信息,JSON格式字符串",
|
||||
type: "json"
|
||||
tooltip: `可以选择性读取其中的某一个属性,如{{WindowInfo.id}}`,
|
||||
type: "json",
|
||||
match: /{{WindowInfo(\.\w{1,7}){0,1}}}/mg,
|
||||
repl: jsonVar => handlingJsonVar(jsonVar, quickcommand.enterData.payload)
|
||||
},
|
||||
SelectFile: {
|
||||
name: "SelectFile",
|
||||
label: "{{SelectFile}}",
|
||||
desc: "文件管理器选中的文件,不支持Linux"
|
||||
desc: "文件管理器选中的文件,不支持Linux",
|
||||
match: /{{SelectFile}}/mg,
|
||||
repl: () => window.getSelectFile(quickcommand.enterData.payload.id)
|
||||
},
|
||||
MatchedFiles: {
|
||||
name: "MatchedFiles",
|
||||
label: "{{MatchedFiles}}",
|
||||
tooltip: `可以选择性读取其中的某一个属性,如{{MatchedFiles[0].path}}`,
|
||||
desc: "匹配的文件,JSON格式字符串",
|
||||
type: "json"
|
||||
type: "json",
|
||||
match: /{{MatchedFiles(\[\d+\]){0,1}(\.\w{1,11}){0,1}}}/mg,
|
||||
repl: jsonVar => handlingJsonVar(jsonVar, quickcommand.enterData.payload)
|
||||
},
|
||||
type: {
|
||||
name: "type",
|
||||
label: "{{type}}",
|
||||
desc: "专业模式的type"
|
||||
desc: "专业模式的type",
|
||||
match: /{{type}}/mg,
|
||||
repl: () => quickcommand.enterData.type
|
||||
},
|
||||
payload: {
|
||||
name: "payload",
|
||||
label: "{{payload}}",
|
||||
desc: "专业模式的payload,JSON格式字符串",
|
||||
type: "json"
|
||||
desc: "专业模式的payload",
|
||||
match: /{{payload}}/mg,
|
||||
repl: () => escapeItem(quickcommand.enterData.payload)
|
||||
}
|
||||
}
|
||||
|
||||
export default specialVars
|
||||
export default specialVars
|
||||
Reference in New Issue
Block a user