baptx

facebook_friends_people_search_backup

Feb 4th, 2020
92
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)
  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. function FacebookFriendsBackup()
  14. {
  15.     var list = document.getElementsByClassName("uiProfileBlockContent");
  16.     var length = list.length;
  17.  
  18.     // note: firstChild is a bit faster than firstElementChild: https://jsperf.com/firstelementchild-and-firstchild
  19.     for (var i = 0; i < length; ++i) {
  20.         var link = list[i].getElementsByTagName("a")[0];
  21.         data[i] = link.firstChild.nodeValue;
  22.         data[i] += "\t" + link.href;
  23.         var json = JSON.parse(link.getAttribute("data-gt"));
  24.         if (json) { // JSON data is null when the Facebook profile is deactivated
  25.             data[i] += "\t" + json.engagement.eng_tid; // get profile ID in case the Facebook user changes their profile URL
  26.         }
  27.     }
  28.    
  29.     displayData();
  30. }
  31.  
  32. // can be used to backup a people search (for example to see when someone from another country or city moves to a new city)
  33. // some results could be missing since sometimes the city name is followed by the region instead of the country
  34. function FacebookPeopleSearchBackup()
  35. {
  36.     //var list = document.getElementById("browse_result_area").getElementsByClassName("FriendRequestOutgoing"); // missing results since friend button is disabled on some profiles
  37.     var list = document.querySelectorAll('#BrowseResultsContainer > div, [data-testid="results"] > div');
  38.     var length = list.length;
  39.    
  40.     for (var i = 0; i < length; ++i) {
  41.         data[i] = JSON.parse(list[i].firstChild.getAttribute("data-bt")).id;
  42.        
  43.         // comment previous line and uncomment following lines if you want full name and profile URL also
  44.         /*var link = list[i].getElementsByTagName("a")[1];
  45.         data[i] = link.title;
  46.         data[i] += "\t" + link.href;
  47.         data[i] += "\t" + JSON.parse(list[i].firstChild.getAttribute("data-bt")).id;*/
  48.     }
  49.    
  50.     displayData();
  51. }
  52.  
  53. // can be used to backup group members with things in common (https://www.facebook.com/groups/XXX/members_with_things_in_common/)
  54. // some results could be missing since sometimes the city uses the original name instead of the translated name
  55. function FacebookPeopleCommonBackup()
  56. {
  57.     var list = document.querySelectorAll("[id^=things_in_common_]");
  58.     var length = list.length;
  59.    
  60.     for (var i = 0; i < length; ++i) {
  61.         data[i] = list[i].id.substr(17);
  62.        
  63.         // comment previous line and uncomment following lines if you want full name and profile URL also
  64.         /*var link = list[i].getElementsByTagName("a")[1];
  65.         data[i] = link.title;
  66.         data[i] += "\t" + link.href;
  67.         data[i] += "\t" + list[i].id.substr(17);*/
  68.     }
  69.    
  70.     displayData();
  71. }
  72.  
  73. function displayData()
  74. {
  75.     var box = document.createElement("textarea");
  76.     box.value = data.join('\n');
  77.     document.body.appendChild(box);
  78. }
RAW Paste Data