Skip to content

Instantly share code, notes, and snippets.

@mape
Created May 11, 2010 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mape/396970 to your computer and use it in GitHub Desktop.
Save mape/396970 to your computer and use it in GitHub Desktop.
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