Guest User

Untitled

a guest
Feb 15th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. function save(data,filename){
  2.  
  3. if(!data) {
  4. console.error('Console.save: No data')
  5. return;
  6. }
  7.  
  8. if(!filename) filename = 'console.json'
  9.  
  10. if(typeof data === "object"){
  11. data = JSON.stringify(data, undefined, 4)
  12. }
  13.  
  14. var blob = new Blob([data], {type: 'text/json'}),
  15. e = document.createEvent('MouseEvents'),
  16. a = document.createElement('a')
  17.  
  18. a.download = filename
  19. a.href = window.URL.createObjectURL(blob)
  20. a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
  21. e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
  22. a.dispatchEvent(e)
  23.  
  24. }
  25.  
  26. function saveJSON(filename){
  27. let texts = document.getElementsByTagName('body')[0].innerText.split('\n')
  28. let json = []
  29.  
  30. for(let i =0;i<texts.length;i++){
  31. let text = texts[i]
  32. if(text == '') continue
  33. json.push({key:text})
  34. }
  35. save(json,filename)
  36. }
Add Comment
Please, Sign In to add comment