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

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 fast, so I completely rewrote it.
What's new:
Link to the repository
The main filtering change is that jQuery is no longer used at all. All comments are written 1 time to the 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 purpose of the script is to limit the number of comments to some finite number. Yes, I understand that rating is not always an indicator and a minus comment may be worth it to read. That is why the script does not hide a single commentuntil you yourself enter a 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. I checked the script 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 talk about. If you have any suggestions or questions, I will be happy to answer in the comments.
UPD:I completely forgot to describe the filtering process. So, if there is a comment with a suitable rating in the branch, then the entire branch before it is open, even if the parents do not fit the rating. At the same time, the button “Show answers” is added to the last comment in the branch so that you can do this if you want to read to the end. Thus, comments are not cut out from the chronology and the thought is not lost just like that, you can also read all the comments in a thread or post.

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 fast, so I completely rewrote it.
What's new:
- rewritten filtering without using $ .each
- the method for calculating the average comment rating has been changed
- added number of displayed comments
- added instant filtering
- support for Firefox and Chrome
- unit tests added
Link to the repository
The main filtering change is that jQuery is no longer used at all. All comments are written 1 time to the 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 purpose of the script is to limit the number of comments to some finite number. Yes, I understand that rating is not always an indicator and a minus comment may be worth it to read. That is why the script does not hide a single commentuntil you yourself enter a 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. I checked the script 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 talk about. If you have any suggestions or questions, I will be happy to answer in the comments.
UPD:I completely forgot to describe the filtering process. So, if there is a comment with a suitable rating in the branch, then the entire branch before it is open, even if the parents do not fit the rating. At the same time, the button “Show answers” is added to the last comment in the branch so that you can do this if you want to read to the end. Thus, comments are not cut out from the chronology and the thought is not lost just like that, you can also read all the comments in a thread or post.