Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // add jquery code here
- // Remove all other posts
- jQuery('[role="feed"]').remove();
- domChangeCounter = 0;
- texts = [];
- function checkForMoreComments()
- {
- clean();
- // Count how many times this function has been called
- domChangeCounter++;
- // Early return if domChangeCounter is more than 10
- if (domChangeCounter > 10)
- {
- complete();
- return;
- }
- // check for a span containing the text "Visa fler kommentarer"
- span = jQuery('span:contains("Visa fler kommentarer")')
- // Run process function if any such span was found
- if (span.length > 0) {
- process();
- } else {
- // If no such span was found, try again in 100ms
- // call the function again after 100 milliseconds
- setTimeout( checkForMoreComments, 200 );
- }
- }
- function clean() {
- // Remove the second div of each li element
- // The second div is the one containing the sub comments
- jQuery('li>div:nth-child(2)').remove();
- // Find all comment texsts
- var newTexts = jQuery('[style="text-align: start;"]').map(function() {
- return jQuery.trim(jQuery(this).text());
- }).get();
- // remove texts that are not four words
- newTexts = jQuery.grep(newTexts, function(text) {
- return text.split(' ').length == 4;
- });
- // Print the new total, so that there's something there if the page crashes.
- if (newTexts.length > 0) {
- console.log('Adding ' + newTexts.length + ' texts. Now up to '+texts.length+' texts:\n\n' + texts.join('\n'));
- // add newTexts to texts
- texts = texts.concat(newTexts);
- }
- // Remove the recently processed comments to save memory(?)
- jQuery('li').remove();
- // Scroll to bottom of the page
- window.scrollTo(0,document.body.scrollHeight);
- }
- function process() {
- // Reset domChangeCounter
- domChangeCounter = 0;
- // Fetch more comments
- jQuery('span:contains("Visa fler kommentarer")').click();
- setTimeout( clean, 500 );
- // Call checkDOMChange again after 1.5 seconds
- setTimeout( checkForMoreComments, 1500 );
- }
- function complete() {
- // Console log each text in the array texts
- texts.forEach(function(text) {
- console.log(text);
- });
- alert('Complete! ' + texts.length + ' texts found.');
- }
- checkForMoreComments();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement