Skip to content

Instantly share code, notes, and snippets.

@pinuke
Last active June 3, 2022 23:42
Show Gist options
  • Save pinuke/de5700acc13b05a400166419ae738856 to your computer and use it in GitHub Desktop.
Save pinuke/de5700acc13b05a400166419ae738856 to your computer and use it in GitHub Desktop.
A devtools script for printing/downloading/copying MS Teams Chats
let frames = {
"chat" : document.querySelector( '[id^="experience-container"]' )
}
let documents = {
"chat" : frames.chat.contentWindow.document
}
let clone_to_html_el = function(){
let source_elm = documents.chat.body.parentNode
let source_text = source_elm.innerHTML
let clone = document.createElement( "html" )
clone.innerHTML = source_text
let head = clone.querySelector( "head" )
let body = clone.querySelector( "body" )
let id;
let styles = head.querySelectorAll( "style" )
styles.forEach( ( style, index )=>{ if( style.id == "splash-styles" ) id = index })
let bad_styles = [
styles[ id-2 ],
styles[ id-1 ]
]
let bad_elements = body.querySelectorAll( "button, img, svg" )
bad_styles.forEach( elm => { elm.remove() } )
bad_elements.forEach( elm => { elm.remove() } )
frames.clone = clone
document.body.parentNode.innerHTML = clone.innerHTML
console.log( "to go back, just refresh the page" )
}
clear()
console.log( "before using, make sure to scroll up/down in the teams chat to load in the chat history you want to print/copy" )
console.log( "to run the script copy and paste the following into the console:" )
console.log( "\n\tclone_to_html_el()" )
@pinuke
Copy link
Author

pinuke commented Jun 3, 2022

Open the chat you want to dump in browser. Copy and paste this into devtools. Boom. You have chat dump.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment