修复搜索反馈慢的问题.
This commit is contained in:
parent
4e03832cdc
commit
80c5e187fa
63
index.js
63
index.js
|
|
@ -1,63 +0,0 @@
|
|||
var alfy = require('alfy');
|
||||
function isSreachIndexOF(oldstr,kw){
|
||||
var istrue = false;
|
||||
if(oldstr&&toString.call(oldstr) === '[object Array]'){
|
||||
for (var i = 0; i < oldstr.length; i++) {
|
||||
oldstr[i].toLowerCase()===kw.toLowerCase()?istrue=true:null;
|
||||
}
|
||||
return istrue;
|
||||
}
|
||||
if(!oldstr || !kw) return false;
|
||||
return oldstr.toLowerCase().indexOf(kw.toLowerCase()) > -1 ? true : false;
|
||||
}
|
||||
|
||||
var urlstr = 'git.oschina.net/JSLite/linux-command/raw/master/dist/data.json'
|
||||
// var urlstr = 'http://git.oschina.net/JSLite/linux-command/raw/master/dist/data.json'
|
||||
|
||||
alfy.fetch(urlstr).then(result => {
|
||||
var commands = [];
|
||||
var e = 0
|
||||
for(var a in result){
|
||||
++e;
|
||||
result[a]['id'] = e;
|
||||
commands.push(result[a])
|
||||
}
|
||||
var i=0,
|
||||
page_size = commands.length,
|
||||
arrResult = [],
|
||||
query=alfy.input;
|
||||
if(commands&&commands.length&&toString.call(commands).indexOf('Array')>-1){
|
||||
var count = 0
|
||||
for (; i < page_size; i++) {
|
||||
if(isSreachIndexOF(commands[i].n,query)
|
||||
|| isSreachIndexOF(commands[i].d,query)
|
||||
){
|
||||
if(count < page_size){
|
||||
arrResult.push(commands[i]);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var items = [];
|
||||
for(var i = 0;i< arrResult.length;i++){
|
||||
items.push({
|
||||
title: arrResult[i].n,
|
||||
subtitle: arrResult[i].d,
|
||||
arg: arrResult[i].n
|
||||
})
|
||||
}
|
||||
|
||||
if(items.length < 1){
|
||||
items.push({
|
||||
title: "没有搜素到内容",
|
||||
subtitle: "请尝试其它关键字",
|
||||
})
|
||||
}
|
||||
alfy.output(items);
|
||||
});
|
||||
// const items = alfy.inputMatches(commands, 'n').map(x => ({
|
||||
// title: x.n,
|
||||
// subtitle: x.d,
|
||||
// arg: x.id
|
||||
// }));
|
||||
48
info.plist
48
info.plist
|
|
@ -4,8 +4,6 @@
|
|||
<dict>
|
||||
<key>bundleid</key>
|
||||
<string>com.linux.command.keywords</string>
|
||||
<key>category</key>
|
||||
<string>Tools</string>
|
||||
<key>connections</key>
|
||||
<dict>
|
||||
<key>AB769D13-5DB9-42BF-A314-2D07384CB3A4</key>
|
||||
|
|
@ -45,25 +43,6 @@
|
|||
<string>Linux Command</string>
|
||||
<key>objects</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>config</key>
|
||||
<dict>
|
||||
<key>browser</key>
|
||||
<string></string>
|
||||
<key>spaces</key>
|
||||
<string></string>
|
||||
<key>url</key>
|
||||
<string>https://jaywcjlove.github.io/linux-command/c/{query}.html</string>
|
||||
<key>utf8</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>type</key>
|
||||
<string>alfred.workflow.action.openurl</string>
|
||||
<key>uid</key>
|
||||
<string>0E764AF0-9350-40B4-8A01-175FAD0D952D</string>
|
||||
<key>version</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>config</key>
|
||||
<dict>
|
||||
|
|
@ -86,10 +65,12 @@
|
|||
<dict>
|
||||
<key>alfredfiltersresults</key>
|
||||
<false/>
|
||||
<key>argumenttrimmode</key>
|
||||
<integer>0</integer>
|
||||
<key>argumenttype</key>
|
||||
<integer>0</integer>
|
||||
<key>escaping</key>
|
||||
<integer>36</integer>
|
||||
<integer>62</integer>
|
||||
<key>keyword</key>
|
||||
<string>lc</string>
|
||||
<key>queuedelaycustom</key>
|
||||
|
|
@ -103,7 +84,9 @@
|
|||
<key>runningsubtext</key>
|
||||
<string>正在搜索中...</string>
|
||||
<key>script</key>
|
||||
<string>./node_modules/.bin/run-node index.js {query}</string>
|
||||
<string>/usr/local/bin/node <<-'CODE'
|
||||
require("./linux")("{query}");
|
||||
CODE</string>
|
||||
<key>scriptargtype</key>
|
||||
<integer>0</integer>
|
||||
<key>scriptfile</key>
|
||||
|
|
@ -124,6 +107,25 @@
|
|||
<key>version</key>
|
||||
<integer>2</integer>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>config</key>
|
||||
<dict>
|
||||
<key>browser</key>
|
||||
<string></string>
|
||||
<key>spaces</key>
|
||||
<string></string>
|
||||
<key>url</key>
|
||||
<string>https://jaywcjlove.github.io/linux-command/c/{query}.html</string>
|
||||
<key>utf8</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>type</key>
|
||||
<string>alfred.workflow.action.openurl</string>
|
||||
<key>uid</key>
|
||||
<string>0E764AF0-9350-40B4-8A01-175FAD0D952D</string>
|
||||
<key>version</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
</array>
|
||||
<key>readme</key>
|
||||
<string>Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。</string>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
const data = require('./data.json');
|
||||
|
||||
module.exports = function (query) {
|
||||
var commands = [];
|
||||
Object.keys(data).forEach(function (keyName) {
|
||||
if (keyName.toLowerCase().indexOf(query) > -1) {
|
||||
const cmd = data[keyName];
|
||||
commands.push({
|
||||
title: cmd.n,
|
||||
subtitle: cmd.d,
|
||||
});
|
||||
}
|
||||
});
|
||||
commands = commands.map(function (item) {
|
||||
item.len = item.title.length;
|
||||
return item;
|
||||
}).sort(function (a, b) {
|
||||
return a.len - b.len;
|
||||
}).map(function(item) {
|
||||
return { title: item.title, subtitle: item.subtitle, arg: item.title };
|
||||
}).slice(0, 8);
|
||||
if (commands.length === 0) {
|
||||
commands.push({
|
||||
title: "没有搜素到内容",
|
||||
subtitle: "请尝试其它关键字",
|
||||
});
|
||||
}
|
||||
|
||||
const result = { items: commands };
|
||||
console.log(JSON.stringify(result));
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "alfred-linux-command",
|
||||
"version": "1.0.0",
|
||||
"version": "1.2.2",
|
||||
"description": "Search through the Linux command.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
|
@ -30,8 +30,5 @@
|
|||
"node": ">=4"
|
||||
},
|
||||
"author": "kenny wang <wowohoo@qq.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"alfy": "^0.6.0"
|
||||
}
|
||||
"license": "MIT"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue