(A jQuery Question about filtering stuff on StackOverflow. I swear, it doesn't belong on Meta!)
Question
I am looking to use a Greasemonkey script to filter the questions on the Home, Questions, and Unanswered Page. Right now I have a solution for it (below), but it takes a few seconds to process, and I was wondering if there is a better way.
Background
If you haven't taken a look at the structure of the home page, it is very similar to this:
(simplified for question purposes)
<div class="question-summary">
<div class="status">
<div class="mini-counts">1</div>
<div>answers</div>
</div>
</div>
and this is the structure of the questions/unanswered page:
<div class="question-summary">
<div class="status">
<strong>1</strong>
answers
</div>
</div>
Now, I need to grab the '1' (the number of answers) out of each question, and check if it is above a certain number. Currently I'm using this code:
function filterByAnswer(number)
{
$.each($('.question-summary'), function()
{
//
if($('.status .mini-counts',this))
{
var answers = $('.status .mini-counts',this).text();
}
else if($('.status strong',this))
{
var answers = $('.status strong',this).text();
}
if(answers > number)
{
$(this).hide();
}
});
}
My Question is, is there a faster way to do this? I found that this take a few seconds to process, and would like a snappier solution.
Thanks for any help you can provide!