Created
May 11, 2010 06:04
-
-
Save mape/396970 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys'), | |
dom = require(__dirname + '/../../lib/level1/core').dom.level1.core, | |
fs = require('fs'), | |
http = require('http'); | |
var window = global.window = require(__dirname + '/../../lib/browser').windowAugmentation(dom); | |
var document = global.document = global.window.document; | |
var location = global.location = global.window.location; | |
var navigator = global.navigator = { | |
userAgent: 'node-js' | |
}; | |
global.window.document.compareDocumentPosition = function () {}; | |
dom.Node.prototype.addEventListener = window.addEventListener = window.document.addEventListener = function () {}; | |
fs.readFile(__dirname + '/jquery.js', function (err, data) { | |
if (err) { | |
throw err; | |
} | |
try { | |
eval(data.toString()); | |
} | |
catch (e) { | |
sys.puts(sys.inspect(e.stack, true)); | |
} | |
$ = window.jQuery; | |
var client = http.createClient(80, 'nodejs.org'); | |
var request = client.request('GET', '/api.html', { | |
'host': 'nodejs.org' | |
}); | |
request.addListener('response', function (response) { | |
var body = ''; | |
response.setEncoding('utf8'); | |
response.addListener('end', function (chunk) { | |
parseInfo(body); | |
}); | |
response.addListener('data', function (chunk) { | |
body += chunk;; | |
}); | |
}); | |
request.end(); | |
function parseInfo(src) { | |
var info = []; | |
$(document.body).html(src); | |
$('h2').each(function (index) { | |
info.push($(this).text()) | |
}); | |
sys.p(info); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment