proginosko / LeechBlockNG

LeechBlock NG (Next Generation) for Firefox is a simple productivity tool designed to block those time-wasting sites that can suck the life out of your working day. All you need to do is specify which sites to block and when to block them.
https://www.proginosko.com/leechblock/
Mozilla Public License 2.0
723 stars 66 forks source link

Keyword blocking detecting words outside of site content #254

Closed fmorroni closed 2 years ago

fmorroni commented 2 years ago

Description

Keywords are detected outside of site content. For example if I add a keyword like ~translate3d, and go into github.com, the site will be blocked. This is because in the html styling of the site the translate3d function is used, and leechblock detects this. I think everyone will agree that this shouldn't be the intended effect.

I believe the issue is with the checkKeyword function at content.js. I declared the function in devtools (with some modifications to print more information) and used it to search for translate3d:

image

As you can see, the function detects the css styling in the head of the html, and probably other things that doesn't make sense for it to detect.

Steps to reproduce

Check the html of any site for words in the styling (I've only tried with styling in the head, I don't know if it works with inline styles) that can't be found anywhere in the content of the site. Add that word as a keyword in a block. The site will get blocked.

image image

Possible solutions

I think the keyword search should only be done on the the body's innerText property. That way only the actual site's content will be used to block and not unrelated stuff from its html.

proginosko commented 2 years ago

Good suggestion! Yes, I think it would be better to search on body.innerText. Let me do some testing on it.

proginosko commented 2 years ago

Implemented in version 1.5. Now only body.innerText is checked for keywords.

fmorroni commented 2 years ago

Implemented in version 1.5. Now only body.innerText is checked for keywords.

Amazing thanks!