Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Display and load all Facebook posts / comments
/* This script will allow you to use the Ctrl+F search function of your web browser to search text in all posts / comments
(without sending your search requests to Facebook and the HTML page can be saved with Ctrl+S as a backup for offline use).
It is also useful if you want to save the content of a Facebook group that requires you to renew a paid membership to remain a member
(video / audio and other files should be downloaded separately) */
// replace with your language translation if needed (case-sensitive)
var moreCommentText = "more comment";
var moreCommentsText = "more comments";
var moreReplyText = "more reply";
var moreRepliesText = "more replies";
var replyText = "Reply";
var repliesText = "Replies";
var seeMoreText = "See More";
// scroll to the bottom of the page or to the limit you want to display before executing (you may need to run the function 2 times to load everything)
function displayLoadAll()
{
// promise chain fixed based on https://stackoverflow.com/questions/66164973/promise-chain-does-not-wait-until-other-promise-is-resolved/66165074#66165074
displayContent()
.then(loadMoreComments)
.then(loadReplies)
.then(loadSeeMore);
}
function displayContent()
{
return new Promise(function(resolve) {
//var list = document.getElementsByClassName("rq0escxv l9j0dhe7 du4w35lb mkhogb32");
var list = document.querySelectorAll(".rq0escxv.l9j0dhe7.du4w35lb.mkhogb32");
var length = list.length;
for (var i = 0; i < length; ++i) {
// unhide content when needed only
if (list[i].hidden) {
console.log("displayContent", i, length);
list[i].removeAttribute("hidden");
list[i].style.display = "block";
}
}
resolve();
});
}
function loadMoreComments()
{
return new Promise(function(resolve) {
//var list = document.getElementsByClassName("d2edcug0 hpfvmrgz qv66sw1b c1et5uql gk29lw5a a8c37x1j keod5gw0 nxhoafnm aigsh9s9 d9wwppkn fe6kdd0r mau55g9w c8b282yb hrzyx87i jq4qci2q a3bd9o3v lrazzd5p m9osqain");
var list = document.querySelectorAll(".d2edcug0.hpfvmrgz.qv66sw1b.c1et5uql.gk29lw5a.a8c37x1j.keod5gw0.nxhoafnm.aigsh9s9.d9wwppkn.fe6kdd0r.mau55g9w.c8b282yb.hrzyx87i.jq4qci2q.a3bd9o3v.lrazzd5p.m9osqain");
var length = list.length;
var i = -1;
function listLoop() {
if (++i < length) {
if (list[i].innerHTML.match(moreCommentText + "|" + moreCommentsText + "|" + moreReplyText + "|" + moreRepliesText + "$")) {
console.log("loadMoreComments", i, length);
// timeout needed to send all requests
setTimeout(function(){
list[i].click();
listLoop();
}, 1000);
}
else {
listLoop();
}
}
else {
resolve();
}
}
listLoop();
});
}
function loadReplies()
{
return new Promise(function(resolve) {
//var list = document.getElementsByClassName("rq0escxv l9j0dhe7 du4w35lb j83agx80 cbu4d94t pfnyh3mw d2edcug0 hpfvmrgz n8tt0mok hyh9befq r8blr3vg jwdofwj8 g0qnabr5");
var list = document.querySelectorAll(".rq0escxv.l9j0dhe7.du4w35lb.j83agx80.cbu4d94t.pfnyh3mw.d2edcug0.hpfvmrgz.n8tt0mok.hyh9befq.r8blr3vg.jwdofwj8.g0qnabr5");
var length = list.length;
var i = -1;
function listLoop() {
if (++i < length) {
if (list[i].innerHTML.match(replyText + "|" + repliesText + "$")) {
console.log("loadReplies", i, length);
// timeout needed to send all requests
setTimeout(function(){
list[i].click();
listLoop();
}, 1000);
}
else {
listLoop();
}
}
else {
resolve();
}
}
listLoop();
});
}
function loadSeeMore()
{
return new Promise(function(resolve) {
//var list = document.getElementsByClassName("oajrlxb2 g5ia77u1 qu0x051f esr5mh6w e9989ue4 r7d6kgcz rq0escxv nhd2j8a9 nc684nl6 p7hjln8o kvgmc6g5 cxmmr5t8 oygrvhab hcukyx3x jb3vyjys rz4wbd8a qt6c0cv9 a8nywdso i1ao9s8h esuyzwwr f1sip0of lzcic4wl oo9gr5id gpro0wi8 lrazzd5p");
// use querySelectorAll instead of getElementsByClassName since it returns a static list instead of a live list (to avoid undefined error when links are clicked and removed from the DOM)
var list = document.querySelectorAll(".oajrlxb2.g5ia77u1.qu0x051f.esr5mh6w.e9989ue4.r7d6kgcz.rq0escxv.nhd2j8a9.nc684nl6.p7hjln8o.kvgmc6g5.cxmmr5t8.oygrvhab.hcukyx3x.jb3vyjys.rz4wbd8a.qt6c0cv9.a8nywdso.i1ao9s8h.esuyzwwr.f1sip0of.lzcic4wl.oo9gr5id.gpro0wi8.lrazzd5p");
var length = list.length;
var i = -1;
function listLoop() {
if (++i < length) {
if (list[i].innerHTML == seeMoreText) {
console.log("loadSeeMore", i, length);
// timeout not needed unless there is a robot detection to bypass (data already present)
//setTimeout(function(){
list[i].click();
listLoop();
//}, 1000);
}
else {
listLoop();
}
}
else {
resolve();
}
}
listLoop();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment