Skip to content

Instantly share code, notes, and snippets.

@chitacan
Created August 16, 2013 09:00
Show Gist options
  • Save chitacan/6248369 to your computer and use it in GitHub Desktop.
Save chitacan/6248369 to your computer and use it in GitHub Desktop.
chrome devtools snippet to print script tag info.
(function() {
var scripts = document.getElementsByTagName('script');
var table = [];
function Row(){
this.name = ''; // inlined or name
this.src = '';
this.async = false;
this.etc = '';
}
function removeQuery(url) {
return url.split('?')[0];
}
function getResourceName(url) {
var s = url.split('/');
if (s.length > 3) {
return removeQuery(s.pop());
} else {
return '(noname)';
}
}
function getRow(el) {
var nnm = el.attributes;
var row = new Row();
if (nnm == null)
return row;
if (el.text) {
row.name = '(noname)';
row.src = '(inlined)';
return row;
}
for (var i = 0 ; i < nnm.length ; i++) {
var n = nnm[i];
switch(n.name) {
case 'src':
row.name = getResourceName(n.value);
row.src = 'linked';
break;
case 'async':
row.async = true;
break;
default:
row.etc = (row.etc.length === 0 ? n.name : ', ' + n.name);
break;
}
}
return row;
}
for(var i = 0 ; i < scripts.length ; i++) {
var nnm = scripts[i].attributes;
table.push(getRow(scripts[i]));
}
console.dir(scripts);
console.table(table);
console.log("Navigate to elemnent with %c'inspect(document.getElementsByTagName('script')[index])'", 'color:orange');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment