Created
August 1, 2012 06:15
-
-
Save westonruter/3224206 to your computer and use it in GitHub Desktop.
Run this script from console (or package as a bookmarklet) to export comments into a new window, suitable for inserting into a Google Doc
This file contains 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
javascript: (function(){ var script = document.createElement('script'); script.src = "https://raw.github.com/gist/3224206/facebook-comment-exporter.js"; document.body.appendChild(script); }()) |
This file contains 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(){ | |
"use strict"; | |
var comment_export_win = window.open('about:blank'); | |
[].forEach.call(document.querySelectorAll('.text_exposed_link a'), function (el) { | |
el.onclick(); | |
}); | |
[].forEach.call(document.querySelector('.uiCommentContainer').querySelectorAll('.commentList > li'), function (li) { | |
var comment_content = li.querySelector('.commentContent'); | |
var text_exposed_hides = comment_content.querySelectorAll('.text_exposed_hide'); | |
[].forEach.call(text_exposed_hides, function (text_exposed_hide) { | |
text_exposed_hide.parentNode.removeChild(text_exposed_hide); | |
}); | |
var text_exposed_show = comment_content.querySelector('.text_exposed_show'); | |
if (text_exposed_show) { | |
while (text_exposed_show.firstChild) { | |
text_exposed_show.parentNode.appendChild(text_exposed_show.firstChild); | |
} | |
text_exposed_show.parentNode.removeChild(text_exposed_show); | |
} | |
comment_content.normalize(); | |
var name = comment_content.querySelector('.actorName').textContent; | |
var comment_body = comment_content.querySelector('.commentBody').cloneNode(true); | |
var comment_permalink = li.querySelector('.commentActions > .uiLinkSubtle').cloneNode(true); | |
comment_permalink.setAttribute('href', comment_permalink.href); | |
comment_permalink.textContent = comment_permalink.querySelector('abbr').title; | |
var p = document.createElement('p'); | |
p.appendChild(comment_permalink); | |
comment_body.insertBefore(p, comment_body.firstChild); | |
var name_el = document.createElement('h3'); | |
name_el.appendChild(document.createTextNode(name + ': ')); | |
comment_body.insertBefore(name_el, comment_body.firstChild); | |
comment_export_win.document.body.appendChild(comment_export_win.document.importNode(comment_body, true)); | |
comment_export_win.document.body.appendChild(comment_export_win.document.createElement('hr')); | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment