In order to do network analysis on Facebook's graph, sometimes it was necessary to load every member of a Facebook group. This script simply automated the scrolling so the members could be copy-pasted and names/their IDs be used in analysis.

read more
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

on scrolldem(id, needToClickShowMembers)
	
	
	tell application "Safari"
		set doc to front document
		set done_loading to false
		do JavaScript "
		window.location.assign('" & id & "');
		" in doc
		delay 1
	end tell
	
	
	
	tell application "Safari"
		repeat while done_loading is not equal to true
			set doc to front document
			set done_loading to do JavaScript "
			var done = false;
			 if (document.readyState=='complete'){
			 	done=true;
			}
			
			done;
				" in doc
			delay 1
		end repeat
	end tell
	
	if needToClickShowMembers then
		tell application "Safari"
			
			set doc to front document
			set done_loading to do JavaScript "
			var aTags = document.getElementsByTagName('a');
			 var searchText = 'See All';
			var found;

	for (var i = 0; i < aTags.length; i++) {
	  if (aTags[i].textContent == searchText) {
	    found = aTags[i];
		if(found.getAttribute('href').includes('group_members')){ 
		   found.click();
	   }
	   
	  }
	}
  
	  
				" in doc
			delay 1
			
		end tell
		
	end if
	
	if not needToClickShowMembers then
		
		tell application "Safari"
			set doc to front document
			set this_url to URL of doc
			set done_scrolling to false
			set filtered_URLs to {}
			set completed_once to false
			set erred_once to false
			
			
			
			set done_scrolling to do JavaScript "
		
		var completed_once = " & completed_once & ";
		if(completed_once!=true){
		var done;
		var number_of_trys =0;
		}
    function scrollToBottom(){
      bottom = document.body.scrollHeight;
      current = window.innerHeight+ document.body.scrollTop;
	done = false;
      if((bottom-current) >0){
        window.scrollTo(0, bottom);
        setTimeout (scrollToBottom, 2500 ); //If the loading exceeds this timeout, a try will be used.
	 var aTags = document.getElementsByTagName('a');
	 var searchText = 'See More';
	var found;

	for (var i = 0; i < aTags.length; i++) {
	  if (aTags[i].textContent == searchText) {
	    found = aTags[i];
	   found.click();
	    break;
	  }
	}
      }
	  else {
			done = true;	
			alert('might be done? Stop the script if we actually are.');
			setTimeout (scrollToBottom, 5500 );
	  }
    };
	if(completed_once!=true){
   	 scrollToBottom();
	}
	
	if(done==true&&number_of_trys<50){//This number changes the number of allowed timeouts
		done=false;
		number_of_trys++;
		setTimeout(scrollToBottom, 1000);
		//This number sets the allotted timeout length.
		//If the loading exceeds both the timeout above and this timeout, another try will be used immediately.
	}
	
	done;
	
    " in doc
			
			set completed_once to true
			delay 0.2
			
			
			
			
		end tell
		
	else
		
		
		tell application "Safari"
			set doc to front document
			set this_url to URL of doc
			set done_scrolling to false
			set filtered_URLs to {}
			set completed_once to false
			set erred_once to false
			
			
			repeat while done_scrolling is not equal to true
				set done_scrolling to do JavaScript "
		
		var completed_once = " & completed_once & ";
		if(completed_once!=true){
		var done;
		var number_of_trys =0;
		}
   
	 function scrollToBottom(){
      bottom = document.body.scrollHeight;
      current = window.innerHeight+ document.body.scrollTop;
	done = false;
	
	var container = document.getElementsByClassName('fbProfileBrowserListContainer')[0];
	var found;
	  
	 var aTags = document.getElementsByTagName('a');
	 var searchText = 'See More';
	var found;
	var weGotIt = false;
	for (var i = 0; i < aTags.length; i++) {
	  if (aTags[i].textContent == searchText) {
	    found = aTags[i];
		if(found.getAttribute('href').includes('group_members')){ 
		  found.click();
	       weGotIt = true;
           setTimeout (scrollToBottom, 2500 ); //If the loading exceeds this timeout, a try will be used.
		}
	  }
  }
	
	
	if(weGotIt == false){
		alert('might be done? Stop the script if we actually are.');
	}
     
    };
	if(completed_once!=true){
   	 scrollToBottom();
	}
	
	
	done;
	
    " in doc
				
				set completed_once to true
				delay 0.2
				
				
				
			end repeat
		end tell
		
		
	end if
end scrolldem
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
set processCancelled to false
set requestingStartingID to display dialog "What is the page you want to scroll?" default answer "https://www.facebook.com" with title "Scroller" buttons {"I'm in the group", "I'm not in the group"} default button 1
set button_pressed to the button returned of the result
if the button_pressed is "I'm in the group" then
	set needToClickShowMembers to false
else
	set needToClickShowMembers to true
end if
set startingID to text returned of requestingStartingID
if processCancelled is equal to false then
	scrolldem(startingID, needToClickShowMembers)
end if