Created
July 8, 2012 21:43
-
-
Save jelmervdl/3073015 to your computer and use it in GitHub Desktop.
Some snippets to store facebook chat history.
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
window.conversation = (function() { | |
var conversation = []; | |
Array.prototype.forEach.call( | |
document.querySelectorAll('#MessagingMessages .MessagingMessage'), | |
function(block) { | |
var sender = block.querySelector('.uiProfilePhoto').getAttribute('alt'); | |
var timestamp = block.querySelector('abbr.timestamp').getAttribute('data-utime'); | |
var messages = []; | |
Array.prototype.forEach.call( | |
block.querySelectorAll('.uiListItem .content'), | |
function(message) { | |
messages.push(message.innerHTML); | |
} | |
); | |
conversation.push({ | |
'sender': sender, | |
'timestamp': timestamp, | |
'messages': messages | |
}); | |
} | |
); | |
return conversation; | |
})(); |
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() { | |
var scrollToTop, scrollToTopTimeout; | |
scrollToTop = function() { | |
document.body.scrollTop = 0; | |
}; | |
document.getElementById('MessagingScroller').addEventListener('DOMSubtreeModified', function(e) { | |
clearTimeout(scrollToTopTimeout); | |
scrollToTopTimeout = setTimeout(scrollToTop, 100); | |
}); | |
scrollToTop(); | |
})(); |
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
var output = window.open(); | |
var pre = output.document.createElement('pre'); | |
output.document.body.appendChild(pre); | |
pre.appendChild(output.document.createTextNode(JSON.stringify(conversation))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment