Last active
April 9, 2018 12:34
-
-
Save JoelRamosM/268f4b022cb285c6b69c9e5ff60e15cb to your computer and use it in GitHub Desktop.
Get CSV of contacts list message Whatsapp
This file contains hidden or 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 getContacts() { | |
| let contatos = document.querySelectorAll("._3afBu"); | |
| var data = []; | |
| for (let index = 0; index < contatos.length; index++) { | |
| const element = contatos[index]; | |
| let nomeElement = element.querySelector("._1wjpf"); | |
| let telElement = element.querySelector(".wRfKo > span") || element.querySelector('.wRfKo'); | |
| let nome = nomeElement.innerHTML; | |
| let tel = (telElement && telElement.innerHTML) || '-----'; | |
| data.push({ nome: nome, tel: tel }); | |
| } | |
| let csvContent = "data:text/csv;charset=utf-8,"; | |
| data.map(e => [e.nome, e.tel]).forEach(e => { | |
| let row = e.join('|'); | |
| csvContent += row + "\r\n"; | |
| }); | |
| console.table(data); | |
| var encodedUri = encodeURI(csvContent); | |
| window.open(encodedUri); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment