📜 ⬆️ ⬇️

Filter for Habrahabr comments in the form of userscript: version 2

Some time ago I wrote a simple userscript that allows you to filter comments on Habré by rating. And now came the 2nd version with new functionality, faster filtering and stable operation in Firefox and Chrome.


The first version of the script was written entirely in jQuery, that is, even the filtering algorithm was based on the use of this library. Naturally, the script did not work quickly, so I rewrote it completely.

What's new:

Repository link

The main filtering change is that jQuery is no longer used at all. All comments are recorded 1 time in an array and further work does not depend on a third-party library. For the sake of interest, I measured the filtering time on an article with 300+ comments: 0.2-0.5 seconds, which is much faster than the time of the previous implementation.
')
Also now the form displays the number of comments shown, which in my opinion is more important than some abstract average rating, because the goal of the script is to limit the number of comments to some finite number. Yes, I understand that the rating is not always an indicator and a well-written comment may be worth reading. That is why the script does not hide any comments until you yourself enter the minimum rating for filtering. It is also possible to open a hidden branch using the "Show Answers" button.

Grunt is used to build a script from several files, and Karma and Jasmine are used for testing. The script was tested in the latest versions of Firefox and Chrome, the installation for these browsers is described in the repository.

That's basically all I wanted to tell you. If you have any suggestions or questions - I will be glad to answer in the comments.

UPD: I completely forgot to describe the filtering process. So, if there is a comment in the branch with a suitable rating, then the entire branch is open to it, even if the parents are not suitable by rating. At the same time, the button “Show answers” ​​is added to the last comment in the branch, so that if you want to read to the end you can do it. Thus, comments are not cut from the chronology and the idea will not be lost just like that, you can also read all the comments in a thread or in a post.

Source: https://habr.com/ru/post/231239/


All Articles