Zetaphor / lemmy-keyword-filter

Do What The F*ck You Want To Public License
2 stars 0 forks source link

Script doesnt apply properly. Must always refresh page or hit save. #1

Open gfigueroap opened 1 year ago

gfigueroap commented 1 year ago

If you filter a new word on any lemmy page, the filter will only work in that page. If you go page 2 of the same community or use lemmy's own search for the keyword, you will still find said filtered keyword. You have to hit F5 or once again click "Save" as indicated on the guide and only then itll work for all cases described.

Naturally, having to refresh the website every time i go to the next page is not ideal. I should be able to set the specific keyword once and forget about it from then on.

jenda69 commented 1 year ago

I added this after filterPostsByKeywords(savedKeywords); (second to last line):

  const callback = function(mutationsList, observer) {
    filterPostsByKeywords(savedKeywords);
  };
  // Create an observer instance linked to the callback function
  const observer = new MutationObserver(callback);
  const config = { childList: true, subtree: true };
  // Start observing the target node for configured mutations
  observer.observe(document.body, config);

It most definitely is not an optimal solution, but it works and is good enough after few minutes of googling and editing. It monitors changes in the body element and everytime there's a change, it runs the filters again.

Zetaphor commented 1 year ago

I can take a look at this later, I'm currently wrapped up in a few other projects.

A more ideal solution would be watching for clicks to the next and previous page buttons and then running the filter. I'm open to PR's if anyone wants to make that change.