Skip to content

Instantly share code, notes, and snippets.

@lucamug
Created December 8, 2016 20:06
Show Gist options
  • Save lucamug/ea38bf8ab81115153372e4b4882e0e02 to your computer and use it in GitHub Desktop.
Save lucamug/ea38bf8ab81115153372e4b4882e0e02 to your computer and use it in GitHub Desktop.
(function() {
function getSource(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
return callback(xhr.responseText);
}
};
xhr.open('GET', url, true);
xhr.send(null);
}
function countScripts(p) {
var count = (p.match(/<script/g) || []).length;
return (count);
}
var url = document.location.href;
getSource(url, function(source) {
console.log(url + "\n\tScripts in source: " + countScripts(source) + "\n\tScripts in DOM: " + document.getElementsByTagName("script").length);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment