Skip to content

Instantly share code, notes, and snippets.

@nym
Created June 21, 2012 17:54
Show Gist options
  • Save nym/2967352 to your computer and use it in GitHub Desktop.
Save nym/2967352 to your computer and use it in GitHub Desktop.
Is it loaded? Is it loaded? Yes it might be. Yes it might be.
var jsdom = require('jsdom');
var fs = require('fs');
var request = require("request");
var jsdom = require("jsdom");
jsdom.defaultDocumentFeatures = {
FetchExternalResources : ['script', 'img', 'css', 'frame', 'link'],
ProcessExternalResources : ['script', 'img', 'css', 'frame', 'link'],
MutationEvents : '2.0',
QuerySelector : false
};
jsdom.env("http://documentcloud.github.com/backbone/examples/todos/index.html",
{
features: {
FetchExternalResources : ['script', 'img', 'css', 'frame', 'link'],
ProcessExternalResources : ['script', 'img', 'css', 'frame', 'link'],
MutationEvents : '2.0',
QuerySelector : false
}
},
function(errors, window) {
var foo, elementsArray, lastScript, fooRunner, runFoo, f, item, loadHandler;
var document = window.document;
runFoo = function(f) {
var fooRunner = function() {
if (f.src) {
console.log(f.src);
//console.log(f);
console.log("---");
console.log();
}
};
setTimeout(fooRunner, 3000);
};
elementsArray = document.getElementsByTagName('script');
console.log(elementsArray.length);
loadHandler = function(){ console.log("Loaded!"); };
for (var i = 0; i<elementsArray.length; i++) {
item = elementsArray[i];
if (typeof(item.src) !== 'undefined') {
item.addEventListener('load', loadHandler, true);
}
try { runFoo(item); }
catch(e) {}
}
console.log("I would like to find out if these scripts were loaded:")
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment