fix: 修复匹配所有文本

This commit is contained in:
fofolee 2022-01-01 11:38:46 +08:00
parent 427037a031
commit 438140b91b
4 changed files with 34 additions and 19 deletions

View File

@ -131,6 +131,7 @@ let getCommandType = cmds => {
if (cmds.length == 1) { if (cmds.length == 1) {
let type = cmds[0].type let type = cmds[0].type
if (!type) return 'key' if (!type) return 'key'
if (type == 'over') return 'regex'
if (type == 'window' || cmds[0].minNum) return type if (type == 'window' || cmds[0].minNum) return type
return 'professional' return 'professional'
} }
@ -438,7 +439,8 @@ let SaveCurrentCommand = async () => {
charset = $('#charset').data() charset = $('#charset').data()
var cmd = window.editor.getValue(); var cmd = window.editor.getValue();
if (tags && tags.includes("默认") && !isDev()) return if (tags && tags.includes("默认") && !isDev()) return
if (!rule) return quickcommand.showMessageBox(`${$('#ruleWord').text().replace(" ", "")} 不能留空!`, 'error') // 留空检测
if (type != "regex" && !rule) return quickcommand.showMessageBox(`${$('#ruleWord').text().replace(" ", "")} 不能留空!`, 'error')
if (!cmdCheck(type, cmd)) return if (!cmdCheck(type, cmd)) return
if (!code) { if (!code) {
// 生成唯一code // 生成唯一code
@ -456,15 +458,24 @@ let SaveCurrentCommand = async () => {
if (type == 'key') { if (type == 'key') {
cmds = rule.split(",").map(x => x.trim()) cmds = rule.split(",").map(x => x.trim())
} else if (type == 'regex') { } else if (type == 'regex') {
if (!/^\/.*?\/[igm]*$/.test(rule)) { // 留空匹配所有文本
rule = "/" + rule + "/" if (!rule) {
cmds = [{
"label": desc,
"type": "over",
"minNum": 1
}];
} else {
if (!/^\/.*?\/[igm]*$/.test(rule)) {
rule = "/" + rule + "/"
}
cmds = [{
"label": desc,
"type": "regex",
"match": rule,
"minNum": 1
}];
} }
cmds = [{
"label": desc,
"type": "regex",
"match": rule,
"minNum": 1
}];
} else if (type == 'window') { } else if (type == 'window') {
var cmdOfWin = { var cmdOfWin = {
"label": desc, "label": desc,
@ -866,25 +877,25 @@ let typeCheck = () => {
case 'key': case 'key':
$("#ruleWord").html("关键字"); $("#ruleWord").html("关键字");
$(".var.regex, .var.window, .var.files").prop("disabled", true) $(".var.regex, .var.window, .var.files").prop("disabled", true)
$("#rule").prop("placeholder", '多个关键字用逗号隔开'); $("#rule").prop("placeholder", 'mycommand,cs');
break; break;
case 'regex': case 'regex':
$("#ruleWord").html("正 则"); $("#ruleWord").html("正 则");
$(".var.window, .var.files").prop("disabled", true) $(".var.window, .var.files").prop("disabled", true)
$(".var.regex").prop("disabled", false) $(".var.regex").prop("disabled", false)
$("#rule").prop("placeholder", '匹配文本的正则,如 /.*?\\.exe$/i'); $("#rule").prop("placeholder", '例:/\\d{18}/,留空匹配所有文本');
break; break;
case 'files': case 'files':
$("#ruleWord").html("正 则"); $("#ruleWord").html("正 则");
$(".var.regex, .var.window").prop("disabled", true) $(".var.regex, .var.window").prop("disabled", true)
$(".var.files").prop("disabled", false) $(".var.files").prop("disabled", false)
$("#rule").prop("placeholder", '匹配文件的正则,如 /.*?\\.exe$/i'); $("#rule").prop("placeholder", '例:/.*?\\.exe$/i');
break; break;
case 'window': case 'window':
$("#ruleWord").html("进 程"); $("#ruleWord").html("进 程");
$(".var.regex, .var.files").prop("disabled", true) $(".var.regex, .var.files").prop("disabled", true)
$(".var.window").prop("disabled", false) $(".var.window").prop("disabled", false)
$("#rule").prop("placeholder", '多个窗口进程逗号隔开'); $("#rule").prop("placeholder", 'word.exe,excel.exe');
break; break;
case 'professional': case 'professional':
$("#ruleWord").html("配 置"); $("#ruleWord").html("配 置");

View File

@ -128,8 +128,13 @@ let showCommandByType = features => {
} else { } else {
let rules = cmds[0].match let rules = cmds[0].match
if (type == 'regex') { if (type == 'regex') {
if (rules.length > 14) rules = rules.slice(0, 14) + '...'; qcType += `<div class="topchild">文本</div><div>`
qcType = `<div class="topchild">正则</div><div><span class="keyword re">${window.htmlEncode(rules, true)}</span></div>`; if (!rules) {
qcType += `<span class="keyword win">所有文本</span>`
} else {
if (rules.length > 14) rules = rules.slice(0, 14) + '...';
qcType += `<span class="keyword re">${window.htmlEncode(rules, true)}</span></div>`;
}
} else if (type == 'window') { } else if (type == 'window') {
qcType += `<div class="topchild">窗口</div><div>` qcType += `<div class="topchild">窗口</div><div>`
// if (!rules) { // if (!rules) {

View File

@ -20,7 +20,7 @@ let command = {
<p><input type="text" id="code" style="display: none"> <p><input type="text" id="code" style="display: none">
<span class="word">&#12288;</span> <span class="word">&#12288;</span>
<select id="type"></select> <select id="type"></select>
<span class="word" id="ruleWord">关键字</span><input class="customize" type="text" id="rule" placeholder="多个关键字用逗号隔开"><img id="expandBtn" src="./img/expand.svg"></p> <span class="word" id="ruleWord">关键字</span><input class="customize" type="text" id="rule" placeholder="mycommand,cs"><img id="expandBtn" src="./img/expand.svg"></p>
<p><span class="word">&#12288;</span><input class="customize" type="text" id="desc" placeholder=""> <p><span class="word">&#12288;</span><input class="customize" type="text" id="desc" placeholder="">
<img id="icon" src=""> <img id="icon" src="">
</p> </p>

View File

@ -5,8 +5,7 @@
"cmds": [ "cmds": [
{ {
"label": "文本处理", "label": "文本处理",
"type": "regex", "type": "over",
"match": "/.*?/",
"minNum": 1 "minNum": 1
} }
], ],
@ -25,4 +24,4 @@
"tags": [ "tags": [
"默认" "默认"
] ]
} }