-
Notifications
You must be signed in to change notification settings - Fork 2
/
justme.js
46 lines (42 loc) · 1.41 KB
/
justme.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
module.exports = function (url, cb) {
var http = require('http');
var sys = require('sys');
var urlbase = 'downforeveryoneorjustme.com';
//Parser. Finding this logic annoying yet? :v
var parser = parsnip(function (e, dom) {
if (e) {
console.log('Error in dfeojm: '+e);
} else {
dom.forEach(function (x) {
x.children.forEach(function (y) {
if (y.name == "head") {
y.children.forEach(function (z) {
if (z.name == "title") {
cb( z.children[0].data );
cb( "http://" + urlbase
+ '/' + url);
}
});
}
});
});
}
});
var client = http.createClient(80, urlbase);
var request = client.request('GET', '/'+url, {host: urlbase});
request.on('response', function (response) {
response.on('data', function (chunk) {
parser.parseChunk(chunk);
});
response.on('end', function() {
parser.done();
});
});
request.end();
}
//htmlparser has a stupid api
//This only helps a LITTLE
function parsnip (cb) {
var htmlparser = require('htmlparser');
return parser = new htmlparser.Parser(new htmlparser.DefaultHandler(cb));
}