// INFO {{{
let INFO =
<>
ninjatottori
New BSD License
Event search on Atnd
-
:atnd
search on atnd
:atnd keyword で補完リストにkeywordで取得したイベントを補完します。
補完リストを使わず、:atnd keyword <Enter> するとMOWに表示します
>;
// }}}
(function(){
commands.addUserCommand(['atnd','atend'], 'atnd.org',
function(args){
if(args.length == 1) {
Atnd.get_events(args);
} else {
liberator.open(args[args.length-1], liberator.NEW_BACKGROUND_TAB);
}
},
{
options : [],
completer : listCompleter,
},
true
);
function listCompleter(context,args){ // {{{
context.title = ["url","title"]
context.filters = [CompletionContext.Filter.textDescription];
context.compare = void 0;
context.anchored = false;
context.incomplete = true;
Atnd.get_event2(context,args);
} //}}}
let Atnd = { //{{{
base_url : "http://api.atnd.org/",
get_events : function(args){ //{{{
let keyword = args.join(",");
if(!keyword) return;
let count = (liberator.globalVariables.atnd_get_count) ? liberator.globalVariables.atnd_get_count : 10 ;
let req = new libly.Request(
this.base_url + "events/?keyword=" + keyword + "&format=json&count=" + count , //url
null, //headers
{ // options
asynchronous:true,
}
);
req.addEventListener("success",function(data){
let res = libly.$U.evalJson(data.responseText);
if(res.results_returned == 0){
liberator.echo("keyword: " + keyword + " was no result");
return;
}
let res_events = res.events.filter(isEnded,new Date())
let html,div = "";
html = +
{res_events.length + "/" + res.results_available + " events matched(include ended events)"}
;
for (let i = 0 ; i < res_events.length ; i++) {
let r = res_events[i]
div += ;
};
liberator.echo(html + div)
function isEnded(elements,index,array){
return ((this - new Date(elements.started_at)) < 0)
}
});
req.addEventListener("failure",function(data){
liberator.echoerr(data.statusText);
});
req.get();
}, //}}}
get_event2 : function(context,args){ //{{{
let keyword = args.join(",");
//if(!keyword) return;
let count = (liberator.globalVariables.atnd_get_count) ? liberator.globalVariables.atnd_get_count : 10 ;
let req = new libly.Request(
this.base_url + "events/?keyword=" + keyword + "&format=json&count=" + count , //url
null, //headers
{ // options
asynchronous:true,
}
);
req.addEventListener("success",function(data){
let res = libly.$U.evalJson(data.responseText);
if(res.results_returned == 0){
return ;
}
let event_data = [];
let res_events = res.events.filter(isEnded,new Date());
for (let i = 0 ; i < res_events.length ; i++) {
let r = res_events[i];
event_data.push([r.event_url,r.title + " " + r.started_at + " " + r.catch + " " + r.address]);
};
context.incomplete = false;
context.completions = event_data;
function isEnded(elements,index,array){
return ((this - new Date(elements.started_at)) < 0)
}
});
req.addEventListener("failure",function(data){
context.incomplete = false;
liberator.echoerr(data.statusText);
});
req.get();
}, // }}}
} // }}}
// for debug
function e(v,c){ // {{{
if(c) util.copyToClipboard(v);
liberator.log(v,-1)
} // }}}
})();
/a>
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|