Last active
December 28, 2015 01:09
-
-
Save kshwetabh/7418106 to your computer and use it in GitHub Desktop.
Chrome Dev Tools Snippets
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
//Great online repo for more snippets: https://bgrins.github.io/devtools-snippets/ | |
/************************************************* | |
//Cache Buster | |
Overwrite all link and (optionally) script tags by adding Date.now() | |
at the end of href and src attributes, respectively. By default processing | |
scripts is not performed, you should change the variable process_scripts | |
to true to run these. | |
/*************************************************/ | |
(function (){ | |
var rep = /.*\?.*/, | |
links = document.getElementsByTagName('link'), | |
scripts = document.getElementsByTagName('script'), | |
process_scripts = false; | |
for (var i=0;i<links.length;i++){ | |
var link = links[i], | |
href = link.href; | |
if(rep.test(href)){ | |
link.href = href+'&'+Date.now(); | |
} | |
else{ | |
link.href = href+'?'+Date.now(); | |
} | |
} | |
if(process_scripts){ | |
for (var i=0;i<scripts.length;i++){ | |
var script = scripts[i], | |
src = script.src; | |
if(rep.test(src)){ | |
script.src = src+'&'+Date.now(); | |
} | |
else{ | |
script.src = src+'?'+Date.now(); | |
} | |
} | |
} | |
})(); | |
/************************************************* | |
//console-save.js | |
A simple way to save objects as .json fle from the console, | |
includes a chrome extension along with a plain script. | |
Usage | |
console.save(data, [filename]) | |
*************************************************/ | |
(function(console){ | |
console.save = function(data, filename){ | |
if(!data) { | |
console.error('Console.save: No data') | |
return; | |
} | |
if(!filename) filename = 'console.json' | |
if(typeof data === "object"){ | |
data = JSON.stringify(data) | |
} | |
var blob = new Blob([data], {type: 'text/json'}), | |
e = document.createEvent('MouseEvents'), | |
a = document.createElement('a') | |
a.download = filename | |
a.href = window.URL.createObjectURL(blob) | |
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':') | |
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null) | |
a.dispatchEvent(e) | |
} | |
})(console) | |
/************************************************* | |
formcontrols.js # (view raw) | |
Shows all html form elements with their values and types in a nice table. | |
Adds a new table for each form on the page. Implementation by Kienz. | |
// 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 = [ ]; | |
console.group("HTMLForm quot;" + forms[i].name + "quot;: " + forms[i].action); | |
console.log("Element:", forms[i], "\nName: "+forms[i].name+"\nMethod: "+forms[i].method.toUpperCase()+"\nAction: "+forms[i].action || "null"); | |
["input", "textarea", "select"].forEach(function (control) { | |
[].forEach.call(forms[i].querySelectorAll(control), function (node) { | |
tab.push({ | |
"Element": node, | |
"Type": node.type, | |
"Name": node.name, | |
"Value": node.value, | |
"Pretty Value": (isNaN(node.value) || node.value === "" ? node.value : parseFloat(node.value)) | |
}); | |
}); | |
}); | |
console.table(tab); | |
console.groupEnd(); | |
} | |
})(); | |
/******************************************************* | |
jquerify.js # (view raw) | |
Includes jQuery onto a page if it is not yet included. | |
// https://github.com/bgrins/devtools-snippets | |
********************************************************/ | |
(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!'); | |
} | |
})(); | |
/******************************************************* | |
log-globals.js # (view raw) | |
Logs your global variables to the console. Useful for finding leaked global variables. | |
log-globals created by Sindre Sorhus. | |
*******************************************************/ | |
(function () { | |
'use strict'; | |
function getIframe() { | |
var el = document.createElement('iframe'); | |
el.style.display = 'none'; | |
document.body.appendChild(el); | |
var win = el.contentWindow; | |
document.body.removeChild(el); | |
return win; | |
} | |
function detectGlobals() { | |
var iframe = getIframe(); | |
var ret = Object.create(null); | |
for (var prop in window) { | |
if (!(prop in iframe)) { | |
ret[prop] = window[prop]; | |
} | |
} | |
return ret; | |
} | |
console.log(detectGlobals()); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment