问题
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)
回答1:
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();
}
});
回答2:
I used AdBlock element hider in the firefox add-on store to figure this out. With a few combinations/try's, I found this combination to work
AdBlock Element Hider selection:
THEAD + * TD:first-child + .text-center.td-fit > P
Current working version:
$("THEAD + * TD:first-child + .text-center.td-fit > P").each(function() {
if ($(this).text() >= 0 && $(this).text() <= 70){
$(this).parent().parent().hide();
}
});
来源:https://stackoverflow.com/questions/40032782/jquery-parent-wont-hide-if-numerical-range-begins-at-0