skaramicke

Download facebook post comments in devtools

Aug 5th, 2021
976
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // add jquery code here
  2.  
  3. // Remove all other posts
  4. jQuery('[role="feed"]').remove();
  5.  
  6. domChangeCounter = 0;
  7. texts = [];
  8.  
  9. function checkForMoreComments()
  10. {
  11.     clean();
  12.  
  13.     // Count how many times this function has been called
  14.     domChangeCounter++;
  15.    
  16.     // Early return if domChangeCounter is more than 10
  17.     if (domChangeCounter > 10)
  18.     {
  19.         complete();
  20.         return;
  21.     }
  22.  
  23.     // check for a span containing the text "Visa fler kommentarer"
  24.     span = jQuery('span:contains("Visa fler kommentarer")')
  25.  
  26.     // Run process function if any such span was found
  27.     if (span.length > 0) {
  28.         process();
  29.     } else {
  30.         // If no such span was found, try again in 100ms
  31.         // call the function again after 100 milliseconds
  32.         setTimeout( checkForMoreComments, 200 );
  33.     }
  34.  
  35. }
  36.  
  37. function clean() {
  38.     // Remove the second div of each li element
  39.     // The second div is the one containing the sub comments
  40.     jQuery('li>div:nth-child(2)').remove();
  41.  
  42.     // Find all comment texsts
  43.     var newTexts = jQuery('[style="text-align: start;"]').map(function() {
  44.         return jQuery.trim(jQuery(this).text());
  45.     }).get();
  46.  
  47.     // remove texts that are not four words
  48.     newTexts = jQuery.grep(newTexts, function(text) {
  49.         return text.split(' ').length == 4;
  50.     });
  51.  
  52.     // Print the new total, so that there's something there if the page crashes.
  53.     if (newTexts.length > 0) {
  54.         console.log('Adding ' + newTexts.length + ' texts. Now up to '+texts.length+' texts:\n\n' + texts.join('\n'));
  55.  
  56.         // add newTexts to texts
  57.         texts = texts.concat(newTexts);
  58.     }
  59.  
  60.     // Remove the recently processed comments to save memory(?)
  61.     jQuery('li').remove();
  62.  
  63.     // Scroll to bottom of the page
  64.     window.scrollTo(0,document.body.scrollHeight);
  65. }
  66.  
  67. function process() {
  68.     // Reset domChangeCounter
  69.     domChangeCounter = 0;
  70.    
  71.     // Fetch more comments
  72.     jQuery('span:contains("Visa fler kommentarer")').click();
  73.  
  74.     setTimeout( clean, 500 );
  75.  
  76.     // Call checkDOMChange again after 1.5 seconds
  77.     setTimeout( checkForMoreComments, 1500 );
  78. }
  79.  
  80. function complete() {
  81.     // Console log each text in the array texts
  82.     texts.forEach(function(text) {
  83.         console.log(text);
  84.     });
  85.  
  86.     alert('Complete! ' + texts.length + ' texts found.');
  87. }
  88.  
  89. checkForMoreComments();
RAW Paste Data