baptx

facebook_friends_people_search_backup

Feb 4th, 2020 (edited)
117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Facebook friends / people search backup in web browser
  2.  * Scroll down to your friends page or a people search page to load all profiles
  3.  * Copy-paste the script below in a web browser console (F12 key or Ctrl+Shift+K shortcut in a browser like Firefox) and execute the desired function
  4.  * A textarea will appear at the end of the page so you can copy the data and paste it in a text file before saving it as a CSV file
  5.  * You can then view your backup in a spreadsheet editor like LibreOffice Calc
  6.  * You can also compare the backup with another one to see who removed you from their friends list or who appeared in a new search (e.g. with the Linux diff command or awk for column diff https://unix.stackexchange.com/questions/174599/using-diff-on-a-specific-column-in-a-file/174603#174603)
  7.  * If the friend changed their name or profile URL, you can still find them with their profile ID which is backed up in the last column (open facebook.com/PROFILE_ID in a web browser)
  8.  * The Facebook Graph API was not used because they are locking or deprecating most of their endpoints (e.g. https://developers.facebook.com/docs/graph-api/changelog/breaking-changes/#taggable-friends-4-4)
  9.  */
  10.  
  11. var data = [];
  12.  
  13. // to make this script work with the new Facebook, you need to open the mobile web version https://m.facebook.com/username/friends
  14. function FacebookFriendsBackup()
  15. {
  16.     var mainList = document.getElementsByClassName("timeline")[0].childNodes[1].childNodes[2].childNodes;
  17.     var mainLength = mainList.length;
  18.    
  19.     for (var i = 0; i < mainLength; ++i) {
  20.         var list = mainList[i].childNodes;
  21.         var length = list.length;
  22.        
  23.         for (var j = 0; j < length; ++j) {
  24.             var link = list[j].getElementsByTagName("a")[1];
  25.             var count = data.length;
  26.             data[count] = link.firstChild.nodeValue;
  27.             data[count] += "\t" + link.href;
  28.             var json = JSON.parse(list[j].firstChild.childNodes[2].firstChild.firstChild.childNodes[2].getAttribute("data-store"));
  29.             data[count] += "\t" + json.id;
  30.         }
  31.     }
  32.    
  33.     displayData();
  34. }
  35.  
  36. // NOT WORKING WITH NEW FACEBOOK (use the updated function above)
  37. function OldFacebookFriendsBackup()
  38. {
  39.     var list = document.getElementsByClassName("uiProfileBlockContent");
  40.     var length = list.length;
  41.  
  42.     // note: firstChild is a bit faster than firstElementChild: https://jsperf.com/firstelementchild-and-firstchild
  43.     for (var i = 0; i < length; ++i) {
  44.         var link = list[i].getElementsByTagName("a")[0];
  45.         data[i] = link.firstChild.nodeValue;
  46.         data[i] += "\t" + link.href;
  47.         var json = JSON.parse(link.getAttribute("data-gt"));
  48.         if (json) { // JSON data is null when the Facebook profile is deactivated
  49.             data[i] += "\t" + json.engagement.eng_tid; // get profile ID in case the Facebook user changes their profile URL
  50.         }
  51.     }
  52.    
  53.     displayData();
  54. }
  55.  
  56. // we need to hook AJAX response with JavaScript to get the profile ID since it is not displayed in the DOM (username is not reliable to backup since it can change)
  57. // execute this function before opening the page and scrolling
  58. // https://stackoverflow.com/questions/5202296/add-a-hook-to-all-ajax-requests-on-a-page/27363569#27363569
  59. function FacebookPeopleSearchBackup()
  60. {
  61.     var count = 0;
  62.  
  63.     var origOpen = XMLHttpRequest.prototype.open;
  64.     XMLHttpRequest.prototype.open = function() {
  65.         if (arguments[1] == "/api/graphql/") {
  66.             this.addEventListener("load", function() {
  67.                 var json = JSON.parse(this.responseText);
  68.                 var list = json.data.serpResponse.results.edges;
  69.                 var length = list.length;
  70.                
  71.                 for (var i = 0; i < length; ++i) {
  72.                     var user = list[i].relay_rendering_strategy.view_model.profile;
  73.                    
  74.                     if (user) {
  75.                         data[count] = user.id;
  76.                        
  77.                         // comment previous line and uncomment following lines if you want full name and profile URL also
  78.                         /*data[count] = user.name;
  79.                         data[count] += "\t" + user.url;
  80.                         data[count] += "\t" + user.id;*/
  81.                        
  82.                         console.log(data[count]);
  83.                         ++count;
  84.                     }
  85.                     else {
  86.                         console.log("END");
  87.                         displayData();
  88.                     }
  89.                 }
  90.             });
  91.         }
  92.         origOpen.apply(this, arguments);
  93.     };
  94. }
  95.  
  96. // NOT WORKING WITH NEW FACEBOOK (use the updated function above)
  97. // can be used to backup a people search (for example to see when someone from another country or city moves to a new city)
  98. // some results could be missing since sometimes the city name is followed by the region instead of the country
  99. function OldFacebookPeopleSearchBackup()
  100. {
  101.     //var list = document.getElementById("browse_result_area").getElementsByClassName("FriendRequestOutgoing"); // missing results since friend button is disabled on some profiles
  102.     var list = document.querySelectorAll('#BrowseResultsContainer > div, [data-testid="results"] > div');
  103.     var length = list.length;
  104.    
  105.     for (var i = 0; i < length; ++i) {
  106.         data[i] = JSON.parse(list[i].firstChild.getAttribute("data-bt")).id;
  107.        
  108.         // comment previous line and uncomment following lines if you want full name and profile URL also
  109.         /*var link = list[i].getElementsByTagName("a")[1];
  110.         data[i] = link.title;
  111.         data[i] += "\t" + link.href;
  112.         data[i] += "\t" + JSON.parse(list[i].firstChild.getAttribute("data-bt")).id;*/
  113.     }
  114.    
  115.     displayData();
  116. }
  117.  
  118. // can be used to backup group members with things in common (https://www.facebook.com/groups/XXX/members_with_things_in_common/)
  119. // some results could be missing since sometimes the city uses the original name instead of the translated name
  120. function OldFacebookPeopleCommonBackup()
  121. {
  122.     var list = document.querySelectorAll("[id^=things_in_common_]");
  123.     var length = list.length;
  124.    
  125.     for (var i = 0; i < length; ++i) {
  126.         data[i] = list[i].id.substr(17);
  127.        
  128.         // comment previous line and uncomment following lines if you want full name and profile URL also
  129.         /*var link = list[i].getElementsByTagName("a")[1];
  130.         data[i] = link.title;
  131.         data[i] += "\t" + link.href;
  132.         data[i] += "\t" + list[i].id.substr(17);*/
  133.     }
  134.    
  135.     displayData();
  136. }
  137.  
  138. function displayData()
  139. {
  140.     var box = document.createElement("textarea");
  141.     box.style = "position: relative; z-index: 1"; // show box on top of other elements (needed for the new Facebook with FacebookPeopleSearchBackup())
  142.     box.value = data.join('\n');
  143.     document.body.appendChild(box);
  144. }
  145.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×