Skip to content

Instantly share code, notes, and snippets.

@OliDM
OliDM / Jquery
Created August 11, 2013 23:59
Add jQuery to any page that does not have it already.
// 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);
@OliDM
OliDM / Log
Created August 12, 2013 00:01
// Adds a `log` function to window object.
// 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);
})();
@OliDM
OliDM / showheaders
Created August 12, 2013 00:02
// Print out response headers for current URL.
// 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);
@OliDM
OliDM / dataurl
Created August 12, 2013 00:03
// Print out data URLs for all images / canvases on the page.
// 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");
@OliDM
OliDM / allcolors
Created August 12, 2013 00:03
// Print out CSS colors used in elements on the page.
// allcolors.js
// https://github.com/bgrins/devtools-snippets
// Print out CSS colors used in elements on the page.
(function () {
var allColors = {};
var props = ["background-color", "color", "border-top-color", "border-right-color", "border-bottom-color", "border-left-color"];
var skipColors = { "rgb(0, 0, 0)": 1, "rgba(0, 0, 0, 0)": 1, "rgb(255, 255, 255)": 1 };
[].forEach.call(document.querySelectorAll("*"), function (node) {
@OliDM
OliDM / performance
Created August 12, 2013 00:05
Print out window.performance information.
// 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 = [];
@OliDM
OliDM / querystringvalues
Created August 12, 2013 00:06
Print out key/value pairs from querystring.
// 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," ") }
@OliDM
OliDM / wrapelement
Created August 12, 2013 00:06
Wrap a given element in a given type of element
// wrapelement.js
// https://github.com/bgrins/devtools-snippets
// Wrap a given element in a given type of element
// wrapElement('.foo', 'h1');
// wrapElement(document.querySelector('#bar'), 'div');
//
// LICENSE: [MIT](http://gkatsev.mit-license.org)
(function() {
window.wrapElement = function(el, whatToWrapIn) {
@OliDM
OliDM / formcontrols
Created August 12, 2013 00:07
// Print out forms and their controls
// formcontrols.js
// https://github.com/bgrins/devtools-snippets
// Print out forms and their controls
(function() {
var forms = document.querySelectorAll("form");
for (var i = 0, len = forms.length; i < len; i++) {
var tab = [ ];
function WatchedProp (obj, prop){
obj["_"+prop] = obj[prop];
// overwrite with accessor
Object.defineProperty(obj, prop, {
get: function () {
return obj["_"+prop];
},