-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
65 lines (57 loc) · 1.28 KB
/
main.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
var AlfredNode = require('alfred-workflow-nodejs');
var actionHandler = AlfredNode.actionHandler;
var workflow = AlfredNode.workflow;
workflow.setName("tvshow-calendar");
var Item = AlfredNode.Item;
var TVDB = require('./tvdb');
var _query;
function filterAndDisplayShows(shows) {
shows
.filter(function (show) {
var re = new RegExp(_query, 'i');
return re.test(show);
})
.forEach(function (show, i) {
var item = new Item({
title: show,
arg: 'query'
});
workflow.addItem(item);
});
workflow.feedback();
}
function filterAndDisplayShortList(shows) {
shows
.forEach(function (show, i) {
var item = new Item({
title: show,
arg: 'query'
});
workflow.addItem(item);
});
workflow.feedback();
}
(function main() {
actionHandler.onAction("shortList", function (query) {
var when;
_query = query;
switch (query) {
case 'yesterday':
when = -1;
break;
case 'tomorrow':
when = 1;
break;
}
TVDB
.getShortShows(when)
.then(filterAndDisplayShortList);
});
actionHandler.onAction("longList", function (query) {
_query = query;
TVDB
.getShows()
.then(filterAndDisplayShows);
});
AlfredNode.run();
})();