computerguy computerguy - 1 month ago 9
Javascript Question

jQuery: .parent() wont hide if numerical range begins at 0

I am having some issues with using a numerical range detection within an element, to then hide another element. It seems to work fine when the range starts at 1+, but it breaks at 0+. Their are different iterations of code I have tried, but so far no luck.

This is the website I am trying to use my greasemonkey script on:
https://openuserjs.org/?orderBy=updated&orderDir=desc

The purpose: I would like to hide a listed item, if it has 0-100 installs.

Here is my script: https://ghostbin.com/paste/zujku

Here are the three variations of code I have tried using but failed:

$("TR .text-center.td-fit").each(function() {
if ($(this).text() >= 0 && $(this).text() <= 100){
$(this).parent().hide();
}
});


$(document).ready(function(){
var tds = $("TR .text-center.td-fit").filter(function() {
return (+$(this).text() > 0 && +$(this).text() < 100);
});
tds.parent().hide();
});


$("TR .text-center.td-fit").each(function() {
if ($(this).text() >= 0 && $(this).text() <= 100){
$(this).parent().hide();
}
});


Note: ".text-center.td-fit" is the 'installs' element on the main list item (TR)

MJH MJH
Answer

Try this:

$("tr.tr-link").each(function() { 
    var num = parseInt($(this).find('td.text-center.td-fit > p').first().text());
    if (num >= 0 && num <= 100) {
        $(this).hide();
    }
});