Created
October 18, 2011 20:18
-
-
Save fzzzy/1296589 to your computer and use it in GitHub Desktop.
use henri's parser from a webworker
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
importScripts('../dom.js'); | |
importScripts('domstr.js'); | |
// Mock up enough fake stuff so that the parser can load | |
// This can be removed once using the non-GWT compiled parser | |
window = { | |
location: {href: "foo"}, | |
setTimeout: function() { | |
return Function.prototype.apply(setTimeout, arguments); | |
}, | |
clearTimeout: function(arg) { | |
return Function.prototype.apply(clearTimeout, arguments); | |
} | |
} | |
document.location = window.location; | |
document.write = function() {} | |
importScripts('parser.js'); | |
var event = document.createEvent('customevent'); | |
event.initEvent('DOMContentLoaded', false, true); | |
document.dispatchEvent(event); | |
document.implementation.mozSetOutputMutationHandler( | |
document, | |
function(evt) { | |
postMessage(JSON.stringify(evt)); | |
} | |
); | |
function GET(url) { | |
var req = new XMLHttpRequest(); | |
req.open("GET", url, false); // in a thread, so blocking ok | |
req.send(''); | |
window.parseHtmlDocument(req.responseText, document, | |
function() { | |
postMessage(JSON.stringify({done: true})); | |
}, | |
null); | |
} | |
onmessage = function(message) { | |
var url = message.data.url.toString(); | |
GET(url); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment