-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgiftcardwiki-webjump.js
30 lines (27 loc) · 1.16 KB
/
giftcardwiki-webjump.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
// giftcardwiki.com webjump with completer
function giftcardwiki_completer () {
keywords(arguments);
completer.call(this, forward_keywords(arguments));
this.get_string = function (x) x.name;
this.get_description = function (x) (x.d*100).toFixed(1) + "% off, " + x.q.toFixed(0) + " cards";
}
giftcardwiki_completer.prototype = {
constructor: giftcardwiki_completer,
__proto__: completer.prototype,
toString: function () "#<giftcardwiki_completer>",
complete: function (input, pos) {
let str = input.substring(0,pos);
let lspec = load_spec({uri: "http://www.giftcardwiki.com/api/v1/gift-cards/search-hints/"});
let result = yield send_http_request(lspec);
let all_data = JSON.parse(result.responseText);
delete this.result;
delete this.lspec;
let c = this;
var narrowed = all_data.filter(function (x) {
let regex = new RegExp(str, 'i');
return regex.test(c.get_string(x));
});
yield co_return(new completions(this, narrowed));
}
};
define_webjump("cardwiki", "http://www.giftcardwiki.com/giftcards/%s", $completer=new giftcardwiki_completer);