Skip to content

Instantly share code, notes, and snippets.

@jkristoffer
Last active September 23, 2016 03:55
Show Gist options
  • Save jkristoffer/cbc40732d1c372478a64edd11e3e0d0a to your computer and use it in GitHub Desktop.
Save jkristoffer/cbc40732d1c372478a64edd11e3e0d0a to your computer and use it in GitHub Desktop.
Chrome Snippets
(() => {
'use strict';
if(!window.hasOwnProperty('jkriss')){
window.jkriss = {};
}
window.jkriss.saveToFile = function(obj){
var text = typeof obj === 'string' ? obj : JSON.stringify(obj);
var blob = new Blob([text], {type:'application/json'});
var url = URL.createObjectURL(blob);
var hiddenAnchorElem = document.createElement('a');
applyAttrs.call(hiddenElement, {
href: url,
target: '_blank',
download: 'console.json'
});
hiddenElement.click();
function applyAttrs( attrs ){
var keys = Object.keys;
keys(attrs).forEach( attr => {
this[attr] = attrs[attr];
});
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment