Created
August 31, 2013 08:35
-
-
Save hkongm/6396946 to your computer and use it in GitHub Desktop.
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
// jquerify.js | |
// https://github.com/bgrins/devtools-snippets | |
// Add jQuery to any page that does not have it already. | |
(function () { | |
if ( !window.jQuery ) { | |
var s = document.createElement('script'); | |
s.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js'); | |
document.body.appendChild(s); | |
console.log('jquery loaded!'); | |
} | |
})(); |
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
// log.js | |
// https://github.com/bgrins/devtools-snippets | |
// Adds a `log` function to window object. | |
// http://www.briangrinstead.com/blog/console-log-helper-function | |
(function() { | |
window.log = Function.prototype.bind.call(console.log, console); | |
})(); |
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
// dataurl.js | |
// https://github.com/bgrins/devtools-snippets | |
// Print out data URLs for all images / canvases on the page. | |
(function() { | |
console.group("Data URLs"); | |
[].forEach.call(document.querySelectorAll("img"), function(i) { | |
var c = document.createElement("canvas"); | |
var ctx = c.getContext("2d"); | |
c.width = i.width; | |
c.height = i.height; | |
try { | |
ctx.drawImage(i, 0, 0); | |
console.log(i, c.toDataURL()); | |
} | |
catch(e) { | |
console.log(i, "No Permission - try opening this image in a new tab and running the snippet again?", i.src); | |
} | |
}); | |
[].forEach.call(document.querySelectorAll("canvas"), function(c) { | |
try { | |
console.log(c, c.toDataURL()); | |
} | |
catch(e) { | |
console.log(c, "No Permission"); | |
} | |
}); | |
console.groupEnd("Data URLs"); | |
})(); |
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
// performance.js | |
// https://github.com/bgrins/devtools-snippets | |
// Print out window.performance information. | |
// https://developer.mozilla.org/en-US/docs/Navigation_timing | |
(function () { | |
var t = window.performance.timing; | |
var timings = []; | |
timings.push({ | |
label: "Time Until Page Loaded", | |
time: t.loadEventEnd - t.navigationStart + "ms" | |
}); | |
timings.push({ | |
label: "Time Until DOMContentLoaded", | |
time: t.domContentLoadedEventEnd - t.navigationStart + "ms" | |
}); | |
timings.push({ | |
label: "Total Response Time", | |
time: t.responseEnd - t.requestStart + "ms" | |
}); | |
timings.push({ | |
label: "Connection", | |
time: t.connectEnd - t.connectStart + "ms" | |
}); | |
timings.push({ | |
label: "Response", | |
time: t.responseEnd - t.responseStart + "ms" | |
}); | |
timings.push({ | |
label: "Domain Lookup", | |
time: t.domainLookupEnd - t.domainLookupStart + "ms" | |
}); | |
timings.push({ | |
label: "Load Event", | |
time: t.loadEventEnd - t.loadEventStart + "ms" | |
}); | |
timings.push({ | |
label: "Unload Event", | |
time: t.unloadEventEnd - t.unloadEventStart + "ms" | |
}); | |
timings.push({ | |
label: "DOMContentLoaded Event", | |
time: t.domContentLoadedEventEnd - t.domContentLoadedEventStart + "ms" | |
}); | |
var navigation = window.performance.navigation; | |
var navigationTypes = { }; | |
navigationTypes[navigation.TYPE_NAVIGATENEXT || 0] = "Navigation started by clicking on a link, or entering the URL in the user agent's address bar, or form submission.", | |
navigationTypes[navigation.TYPE_RELOAD] = "Navigation through the reload operation or the location.reload() method.", | |
navigationTypes[navigation.TYPE_BACK_FORWARD] = "Navigation through a history traversal operation.", | |
navigationTypes[navigation.TYPE_UNDEFINED] = "Navigation type is undefined.", | |
console.group("window.performance"); | |
console.log(window.performance); | |
console.group("Navigation Information"); | |
console.log(navigationTypes[navigation.type]); | |
console.log("Number of redirects that have taken place: ", navigation.redirectCount) | |
console.groupEnd("Navigation Information"); | |
console.group("Timing"); | |
console.log(window.performance.timing); | |
console.table(timings); | |
console.groupEnd("Timing"); | |
console.groupEnd("window.performance"); | |
})(); |
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
// querystringvalues.js | |
// https://github.com/bgrins/devtools-snippets | |
// Print out key/value pairs from querystring. | |
(function() { | |
var url = location; | |
var querystring = location.search.slice(1); | |
var tab = querystring.split("&").map(function(qs) { | |
return { "Key": qs.split("=")[0], "Value": qs.split("=")[1], "Pretty Value": decodeURIComponent(qs.split("=")[1]).replace(/\+/g," ") } | |
}); | |
console.group("Querystring Values"); | |
console.log("URL: "+url+"\nQS: "+querystring); | |
console.table(tab); | |
console.groupEnd("Querystring Values"); | |
})(); |
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
// showheaders.js | |
// https://github.com/bgrins/devtools-snippets | |
// Print out response headers for current URL. | |
(function() { | |
var request=new XMLHttpRequest(); | |
request.open('HEAD',window.location,false); | |
request.send(null); | |
var headers = request.getAllResponseHeaders(); | |
var tab = headers.split("\n").map(function(h) { | |
return { "Key": h.split(": ")[0], "Value": h.split(": ")[1] } | |
}).filter(function(h) { return h.Value !== undefined; }); | |
console.group("Request Headers"); | |
console.log(headers); | |
console.table(tab); | |
console.groupEnd("Request Headers"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment