-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbot-h5p.js
More file actions
57 lines (46 loc) · 1.34 KB
/
dbot-h5p.js
File metadata and controls
57 lines (46 loc) · 1.34 KB
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
var deferred = require('deferred')
, http = require('http');
module.exports = {
description: 'Checks support for given HTML5 feature(s)',
regex: /^html5 (.+)$/,
callback: function(matches) {
var d = deferred()
, browsers = {
firefox: 'Firefox',
opera: 'Opera (desktop)',
op_mob: 'Opera (mobile)',
chrome: 'Chrome',
safari: 'Safari (desktop)',
ios_saf: 'Safari (iOS)',
ie: 'Internet Explorer'
}
, params = {
host: 'api.html5please.com',
port: 80,
method: 'GET',
path: '/' + encodeURIComponent(matches[1]) + '.json?noagent'
}
, req = http.request(params, function (res) {
res.setEncoding('utf8');
var buffer = '';
res.on('data', function (chunk) {
buffer += chunk;
});
res.on('end', function () {
var data = JSON.parse(buffer).result
, result = '';
for (var i in data) {
result += i + ":\n";
for (var j in data[i]) {
if (browsers.hasOwnProperty(j)) {
result += browsers[j] + ': ' + data[i][j] + "\n";
}
}
}
d.resolve(result);
});
});
req.end();
return d.promise;
}
};