zbluebugz / facebook-clean-my-feeds

Clean up Facebook feeds by hiding sponsored, suggestions and other posts based on keywords.
GNU General Public License v3.0
114 stars 13 forks source link

posts array comes up empty #1

Closed moustachedelait closed 2 years ago

moustachedelait commented 2 years ago

This line comes up as an empty array for me let posts = Array.from(document.querySelectorAll('div[data-pagelet*="FeedUnit"]:not([adbpr])'));

I tried out let posts = Array.from(document.querySelectorAll('div[role="feed"] > div:not([adbpr])')); It does find the posts parent divs, but doesn't work out otherwise, it seems to cancel out loading of new posts completely. When I increase the interval to 2 seconds, it works for a bit longer but then also stops loading new posts

zbluebugz commented 2 years ago

Run the following script in the console. The code will print out two lines on how many posts it found.

// -- start of code (news feed)
console.clear();
var posts = Array.from(document.querySelectorAll('div[data-pagelet*="FeedUnit"]'));
console.info("-- News Feed, posts found using 'data-pagelet' query: ", posts.length );
posts = Array.from(document.querySelectorAll('div[role="feed"] > div'));
console.info("-- News Feed, posts found using 'role=feed > div' query: ", posts.length );
// -- end of code (news feed)
moustachedelait commented 2 years ago

News Feed, posts found using 'data-pagelet' query: 0 News Feed, posts found using 'role=feed > div' query: 15

zbluebugz commented 2 years ago

I guess FB is serving you different HTML code structure from me. I'll rewrite the query part of the code to use the 'div[role="feed"] > div'. I'll add a file to the "beta" folder soon - which you can test.

moustachedelait commented 2 years ago

If it helps, here's a pastebin of an ad div. Direct child of the div with role=feed https://pastebin.com/K0xYUgQv

zbluebugz commented 2 years ago

Thanks for the pastebin, it's fairly similar to what I see when viewing non-English version of FB.

I have uploaded another script file, "beta-3-10b.js", in the "beta" folder.

nb: 1) It will filter posts in the News, Groups and Movies/Group feeds. 2) It has variable timings - fast, medium, slow - depending on the number of unprocessed posts found.

Can you let me know if it works for all three feeds?

moustachedelait commented 2 years ago

That seems to work for the main feed, I see ads outlined with orange dots!

In groups I don't get any ads at all...

I'm not sure how to get to Movies feeds, do you have a url to test for that?

zbluebugz commented 2 years ago

Good to hear the ads are blocked in the News Feed.

Yes, the orange dots show up when debugging/testing - highlighting which posts the code will "hide". If you want to actually hide the posts, modify line 72: let HIDE_STYLE = (!true) ...
to
let HIDE_STYLE = (true) ...

As for Groups feed (https://www.facebook.com/groups/feed/), I don't get many ads there, but do get lots of promotions. e.g. "Suggested post from a public group" - from a group that I don't follow. Sometimes I get too many of these and they drown out the posts from groups that I do follow.

As for movies, it's the "Watch" feed - https://www.facebook.com/watch/ - I don't really use this, but do know that ads appear in there.

Marketplace is another one which I'll tackle soon.

moustachedelait commented 2 years ago

Thanks for those urls, there is a lot of facebook pages I never visit.

The watch feed indeed has some sponsored posts and they are recognized correctly.

Post from a public group are not outlined in orange. Here's a pastebin of an example div: https://pastebin.com/SgN5Nwrt

zbluebugz commented 2 years ago

re Groups Feed: Is the promotional text for that post "Post from a public group"?

moustachedelait commented 2 years ago

Yeah, looks to be that way

zbluebugz commented 2 years ago

Hope you don't mind me asking you do to do a small favour, can you test "beta-3-11b.js"? (It's in the beta folder)

The 3.11b_beta code had a big rewrite and should work better than the previous versions.

NB:

moustachedelait commented 2 years ago

It highlights "create room" for removal, is that intentional?

Don't see any highlighting or ads on the marketplace

Have yet to see the pink border

Otherwise seems to work great!

zbluebugz commented 2 years ago

Thanks for the feedback - appreciate it!

1) Create Room: You can enable it to be hidden or not. Change the following: Change lines 237-9:

const CREATE_ROOM = {
  enabled: true // hide the room
};

to:

const CREATE_ROOM = {
  enabled: false // do not hide the room
};

2) Marketplace: Within in each category, the first box is often the Sponsored entry. Snippet of sponsored item: http://prntscr.com/1xbakl1. You'll have to scroll pass "Today's pick" selection of things to sell to see the sponsored stuff. To test if you have the same Marketplace structure as I do, try the following in the console on the Marketplace page - let me know how many items are in the array:

Array.from(document.querySelectorAll('div[data-pagelet="StreamingBrowseFeed"] > div > div'))

3) Pink border No worries, I'll probably remove this option before releasing the code, as it has been a long time since I've seen the particular sponsored post.

zbluebugz commented 2 years ago

New version released (3.11).