One way might be to monkey patch ServerResponse.end like so:
var http = require('http');
var oldEnd = http.ServerResponse.prototype.end,
RE_CONTYPE_HTML = /Content-Type: text\/html/i;
http.ServerResponse.prototype.end = function(data, encoding) {
if (RE_CONTYPE_HTML.test(this._header)) {
if (data)
this.write(data, encoding);
this.write('<script>window.onload = function(){ alert("Hello World!"); };</script>', 'ascii');
oldEnd.call(this);
} else
oldEnd.call(this, data, encoding);
};
http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('<h1>Greetings from node.js!</h1>');
}).listen(8000);