Created
July 20, 2016 13:38
-
-
Save maciejjankowski/dca12bb9ddca0374b14f26190594174e to your computer and use it in GitHub Desktop.
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
(function(){ | |
var msgs = document.querySelectorAll('swx-message'); | |
var mLen = msgs.length; | |
var out = [] | |
for (let i=0; i<mLen; i++){ | |
let r = []; | |
let m = msgs[i]; | |
let user = (m.querySelector('.tileName') && m.querySelector('.tileName').innerText.trim()) || '-'; | |
let timestamp = (m.querySelector('[data-bind^="text: setBottom"]') && m.querySelector('[data-bind^="text: setBottom"]').innerText.trim()) || ''; | |
let content = m.querySelector('.content').innerText.trim().replace(/\n/g,'\\n') || ''; | |
r.push(timestamp, user, content); | |
out.push(r.join('\t')); | |
} | |
csv = out.join('\n'); | |
function getRawCSVBlow(csv){ | |
var bom = decodeURIComponent("%EF%BB%BF");// "\uFEFF\n"; | |
var byteArray = []; | |
csv = bom + csv; | |
csvA = new Uint16Array(csv.split('').map( function(k, v){ | |
return k.charCodeAt(0); | |
})); | |
var blob = new Blob([csvA],{type:'text/csv;charset=UTF-16LE;'}); | |
var blobUrl=URL.createObjectURL(blob); | |
return blobUrl; | |
} | |
function download(filename, text) { | |
var pom = document.createElement('a'); | |
pom.setAttribute('href', text); | |
pom.setAttribute('download', filename); | |
if (document.createEvent) { | |
var event = document.createEvent('MouseEvents'); | |
event.initEvent('click', true, true); | |
pom.dispatchEvent(event); | |
} | |
else { | |
pom.click(); | |
} | |
} | |
download('raport.csv', getRawCSVBlow(csv)); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment