Last active
October 29, 2025 22:12
-
-
Save adamveld12/0a48496b6c873adf418fc3dda4d28007 to your computer and use it in GitHub Desktop.
Export Google Messages content from the browser app.
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 collateMessages(){ | |
| const conversations = []; | |
| const msgRegex = /^(?<sender>[\w\W]+) said: (?<content>[\w\W]+) (?:Sent|Received) on (?<date>[\w\d\s,]+) at (?<time>[\d\:\s]+(?:AM|PM))\.\s?(?<status>Delivered\.)?\s?(?<meta>.*)$/; | |
| const msgEle = document.getElementsByTagName('mws-text-message-part'); | |
| console.log(`fetching ${msgEle.length} messages`); | |
| for (var i = 0; i < msgEle.length; i++) { | |
| const messageContent = msgEle.item(i).getAttribute('aria-label'); | |
| const matches = messageContent.match(msgRegex); | |
| if (!matches?.groups) { | |
| console.warn('this message is special', messageContent); | |
| } else { | |
| const { sender, content, date, time, status, meta } = matches.groups; | |
| const t = new Date(`${date} ${time}`); | |
| conversations.push({ | |
| sender, | |
| content, | |
| time: t.toString(), | |
| timestamp: t.getTime(), | |
| status, | |
| meta, | |
| }); | |
| } | |
| } | |
| console.log(`got ${conversations.length} messages`); | |
| return conversations; | |
| } | |
| function downloadJSON(data, filename = 'data.json') { | |
| const jsonString = JSON.stringify(data); | |
| const blob = new Blob([jsonString], { type: 'application/json' }); | |
| const url = URL.createObjectURL(blob); | |
| const a = document.createElement('a'); | |
| a.href = url; | |
| a.download = filename; | |
| document.body.appendChild(a); | |
| a.click(); | |
| document.body.removeChild(a); | |
| URL.revokeObjectURL(url); | |
| } | |
| const msg = collateMessages(); | |
| downloadJSON(msg); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment