Skip to content

Instantly share code, notes, and snippets.

@jelmervdl
Created July 8, 2012 21:43
Show Gist options
  • Save jelmervdl/3073015 to your computer and use it in GitHub Desktop.
Save jelmervdl/3073015 to your computer and use it in GitHub Desktop.
Some snippets to store facebook chat history.
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;
})();
(function() {
var scrollToTop, scrollToTopTimeout;
scrollToTop = function() {
document.body.scrollTop = 0;
};
document.getElementById('MessagingScroller').addEventListener('DOMSubtreeModified', function(e) {
clearTimeout(scrollToTopTimeout);
scrollToTopTimeout = setTimeout(scrollToTop, 100);
});
scrollToTop();
})();
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