-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy path本地脚本搜索.js
78 lines (65 loc) · 1.99 KB
/
本地脚本搜索.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// 搜索本地脚本
// 按名字匹配,支持多个关键词,以空格分隔
// 搜索结果以菜单形式弹出,点击后执行选中的脚本
// By JunM 2018-01-28
// https://t.me/jun_m
// 脚本分享频道:
// https://t.me/Flow_Script
var addinList = $addin.list;
var totalNumber = addinList.length;
var searchTexts = [];
var searchText = "";
var nameTmp = "";
var searchResults = [];
var re = /\s+/;
$app.tips("\n本地脚本搜索,\n便于脚本数量很多时快速查找; \n\n支持使用多个关键词搜索,\n以空格分隔\n\n点击运行");
$input.text({
placeholder: "请输入关键词,可用空格分隔多个关键词",
handler: function (text) {
if (text === "") {
$ui.alert({
title: "输入值为空,请输入搜索内容",
message: "",
})
$app.close();
} else {
searchTexts = text.split(re);
beginSearch();
}
}
});
function doMatch(tmpScriptName, tmpTextsToSearch) {
for (let i = 0; i <= tmpTextsToSearch.length - 1; i++) {
if ((tmpScriptName.toLowerCase()).indexOf(tmpTextsToSearch[i].toLowerCase()) === -1) {
return -1;
} else {
continue;
}
}
return 1;
}
function beginSearch() {
for (let i = 0; i <= totalNumber - 1; i++) {
nameTmp = addinList[i].name.slice(0, -3);
$console.info(nameTmp);
if (doMatch(nameTmp, searchTexts) !== -1) {
searchResults.push({
scriptID: i,
scriptName: nameTmp
});
}
}
if (searchResults.length === 0) {
$ui.alert({
title: "无满足搜索要求的脚本",
message: "",
})
} else {
$ui.menu({
items: searchResults.map(function (item) { return item.scriptName }),
handler: function (title, idx) {
$addin.run(searchResults[idx].scriptName);
}
})
}
}