Crawl FB group

by Mayank Dixit

JavaScript

/*copy paste jQuery from: https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
 */
var pointer = '<div style="z-index:999; position: fixed; top:50px; left: ' + $('#rightCol').offset().left + 'px;" id="crawl-pointer"> <button style="color: #3a5795; font-size: 40px; cursor: pointer; border-radius: 4px; border: 1px solid gray; background-color: lightyellow;" onclick="togglecrawl()" id="crawl-ctrl">STOP</button></div>';

$('body').append(pointer);

function togglecrawl() {
    if (proceed) {
        proceed = false;
        window.clearInterval(scroller);
        $('#crawl-ctrl').text('START');
        alert("your data is in `groupPosts` array");
    } else {
        proceed = true;
        crawlPost();
        setScroller();
        $('#crawl-ctrl').text('STOP');
    }

}
var groupPosts = [];
var proceed = true;

function scrollTo(to, duration) {
    if (duration < 0) return;
    var scrollTop = document.body.scrollTop + document.documentElement.scrollTop;
    var difference = to - scrollTop;
    var perTick = difference / duration * 10;

    setTimeout(function () {
        scrollTop = scrollTop + perTick;
        document.body.scrollTop = scrollTop;
        document.documentElement.scrollTop = scrollTop;
        if (scrollTop === to) return;
        scrollTo(to, duration - 10);
    }, 10);
}

function setScroller() {
    scroller = window.setInterval(function () {
        scrollTo(document.body.scrollTop + 50, 20);
    }, 100);
}
setScroller();

function crawlPost() {
    if ( !! proceed) {
        post = document.querySelector('._4-u2.mbm._5jmm._5pat');
        if ( !! post) {
            txt = $(post).find('.userContent').text();
            img = $(post).find('.scaledImageFitHeight.img')[0] || $(post).find('img.scaledImageFitWidth')[0] || $(post).find('._46-i.img')[0];
            post_data = {};
            post_data.txt = txt;
            if ( !! img) {
                post_data.img = img.src;
                link = $("<a class='madmad' href=" +...