FreshRSS icon indicating copy to clipboard operation
FreshRSS copied to clipboard

Idea - exclude certain CSS elements from page

Open dddddddavid opened this issue 5 years ago • 14 comments

Excellent programme - I use it all the time to pull full web pages using CSS selector. However, sometimes in the page there are elements I don't want to see, such as newsletter sign-up boxes, 'Most read' etc, and these have their own CSS selector which is consistent within the page. Is it possible to list elements which I don't want shown and for those elements to be dumped.

In the screenshot I've put a red box around two areas, the top one is an email signup form, the bottom one is 'related articles' - both of these appear in every article, and are both inside the article body. Screenshot_2020-06-09_23-48-05

dddddddavid avatar Jun 09 '20 22:06 dddddddavid

@dddddddavid you can leverage the customCSS extension to do that.

aledeg avatar Jun 10 '20 05:06 aledeg

Are there any working examples of rules to accomplish this with the customCSS extension? I have tried with the format .skinny-signup div{display: none;} but without any luck.

dddddddavid avatar Jun 10 '20 11:06 dddddddavid

Can you provide the feed you want to alter?

aledeg avatar Jun 10 '20 11:06 aledeg

https://www.liverpoolecho.co.uk/news/?service=rss

The CSS selector I am using is .content-column

and the additional CSS rules I have tried with the extension are: .skinny-signup div{display: none;} .embedded-image-grid div{display: none;}

dddddddavid avatar Jun 10 '20 11:06 dddddddavid

I'd probably use something like:

div[data-feed="166"] .other-selectors

To make sure it won't affect stuff you don't want affected. That 166 is just whatever ID the feed has.

Where did you get that .skinny-signup thing from? You should right-click on the element in FreshRSS to see what's going on with it.

I tried to do the full content thing with .content-column on that feed above but it doesn't seem to be working for me.

Frenzie avatar Jun 23 '20 13:06 Frenzie

The .skinny-signup is the 'signup for our newsletter' thing which is on all Trinity Mirror sites.

Still can't manage it

dddddddavid avatar Jun 23 '20 13:06 dddddddavid

Okay, it worked on my VPS with the latest release. Not sure if there's something wrong with my local Docker dev instance on my laptop (e.g. insufficient memory or timeout) or with current master.

Anyway, it doesn't look like those class names are taken along. That's probably a conscious decision in the code somewhere. I think I've previously expressed I'd like them to be included with a relevant prefix (like the feed ID) for exactly this reason.

You can still do it with some minor difficulty. The key in any case is to look in FreshRSS, because by that point you're not dealing with the original site.

div[data-feed="243"] div[itemprop="articleBody"] span:first-child,
div[data-feed="243"] div[itemprop="articleBody"] span:first-child+div
{ display: none }

Frenzie avatar Jun 23 '20 16:06 Frenzie

This solution would only work with reading articles within the FreshRSS web app?

A feature I would love is the ability to remove CSS elements from an article that also works with external feed readers as per the 'Article CSS selector' feature.

For example, in the subscription management interface: Article CSS selector: [ .article ] Remove CSS elements: [ .ads, .share-widget ]

Often there are social share widgets, banners etc. in the article that are messy and also interfere with how the article image previews work in external feed readers like Reeder.

kinoushe avatar Sep 28 '20 02:09 kinoushe

A feature I would love is the ability to remove CSS elements from an article that also works with external feed readers as per the 'Article CSS selector' feature.

Yes, that would be awesome! Using the extension doesn't work with external readers and was a real pain to set up (at least for me)...

vocux avatar Oct 27 '20 16:10 vocux

Wouldn't it possible to achieve that using :not() ? : https://developer.mozilla.org/en-US/docs/Web/CSS/:not

I tried without success

SecT0uch avatar Apr 06 '21 10:04 SecT0uch

I've had some success with listing multiple selectors e.g. .c-entry-hero figure, .c-entry-summary, .l-col__main figure, .c-entry-content for https://www.theverge.com/rss/index.xml

Removing elements would be very useful as a feature, though.

I'm not sure how this could be done with a plugin - can you add to a configuration page, such as subscriptions? Or would you need to replace the whole thing?

You would probably use the entry_before_insert hook but the HTML source is 'sanitized' beforehand so there would need to be some changes to Entry.php and it would likely be better as a built-in feature:

			$content->find($SELECTORSTOREMOVE)->remove();
			$html = trim($content->__toString());

drewkerr avatar Jul 20 '21 13:07 drewkerr

This has not been talked about in a while, so I am dropping my comment here to support the implementation of this feature.

Excluding the "Related articles" and other annoying sections would be great.

joelchrono12 avatar Jun 10 '22 16:06 joelchrono12

For all intents and purposes implemented in #4220.

Frenzie avatar Jun 10 '22 17:06 Frenzie

For all intents and purposes implemented in #4220.

It's for 1.20 right? Not in any current release? I'll wait for now :P

joelchrono12 avatar Jun 10 '22 18:06 joelchrono12

https://github.com/FreshRSS/FreshRSS/pull/4501

Alkarex avatar Aug 15 '22 20:08 Alkarex

Implemented. Tests and feedback welcome

Alkarex avatar Aug 15 '22 20:08 Alkarex