1

Noob question here.

Here is my current script:

// ==UserScript==
// @name        hide-unwanted-element
// @include     https:///*
// @description Hides elements I don't want to see in the search result
// @require     http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant       GM_addStyle
// ==/UserScript==

$("h5:contains('Animation Série')").remove();
$("h5:contains('Animation')").remove();
$("h5:contains('Concert')").remove();
$("h5:contains('Documentaire')").remove();
$("div[category-id='2178']").remove();
$("div[category-id='2179']").remove();
$("div[category-id='2180']").remove();
$("div[category-id='2181']").remove();
$(".v3").remove();

I want to hide a lot of h5 that contains different titles, is there a way to optimize the syntax?

Also I want to hide divs with category-id from 2158 up to 2181 with 1 increment, but NOT 2160, 2173, 2175. Same here, I have the feeling that there is better to do it than just listing them one by one, do it?

Thank you very much!

Koolza
  • 11
  • 1

1 Answers1

0

For checking contains for multiple values:

https://stackoverflow.com/a/23248911/2079345

I couldn't find a dupe for selecting ids in a range (maybe someone else can?)

You can use a jquery filter to do it. Select all your divs, then filter on the id by checking that the id is between the 2 numbers, and also that it is not one of your 3 bad numbers (Array.some can help there)

var divsInRange=$('div').filter(function() {
    var id = $(this).attr('id');
    return id >= 2158 && id <= 2181 && !([2160, 2173, 2175].some(function(el) {
        return id == el;
    }));
});
divsInRange.remove();
chiliNUT
  • 18,989
  • 14
  • 66
  • 106