Last active
September 23, 2016 03:55
-
-
Save jkristoffer/cbc40732d1c372478a64edd11e3e0d0a to your computer and use it in GitHub Desktop.
Chrome 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
(() => { | |
'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