-
Notifications
You must be signed in to change notification settings - Fork 2
/
gitee_search.js
65 lines (60 loc) · 1.55 KB
/
gitee_search.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
const item = process.argv[2];
const keyword = process.argv[3];
const https = require("https");
const path = require("path");
const { join } = path;
let content = "";
let result_array = [];
const options = {
"gitee-help": {
host: "gitee.com",
path: "/help/load_keywords_data?id=" + encodeURI(keyword) + "&from=alfred-search",
url: "https://gitee.com/"
}
}[item];
function getData(handleDataFn) {
https.get(options, res => {
res.on("data", chunk => {
content += chunk;
}).on("end", () => {
const jsonContent = JSON.parse(content);
handleDataFn(jsonContent);
});
});
}
function showItem(resultArray) {
content = "";
result_array = [];
console.log(
JSON.stringify({
items: resultArray
})
);
}
if (item === "gitee-help") {
getData(jsonContent => {
const result = jsonContent["data"];
if(result.length===0){
result_array.push({
title: '你搜索的内容暂时找不到啦,试试通过网页查找?',
subtitle: `https://gitee.com/help/`,
arg: `https://gitee.com/help/`,
icon: {
path: join(__dirname, "/79ADC3CD-8339-45F9-B695-704C56412797.png")
}
});
}
const { url } = options;
result.forEach(element => {
result_array.push({
title: element.title,
subtitle: `https://gitee.com${element.href}`,
arg: `https://gitee.com${element.href}`,
icon: {
path: join(__dirname, "/79ADC3CD-8339-45F9-B695-704C56412797.png")
}
});
});
showItem(result_array);
});
}