2

Since IMDB search can't exclude specific genres, I would like to hide the ones who I am not interested in, using Tampermonkey or Greasemonkey.

Every movie is inside a class named "lister-item mode-advanced":

code inspector

Inside that is:

<span class="genre">
Animation, Adventure, Family            </span>

Looking at other answers, I thought something like this could work:

// ==UserScript==
// @name         NoAnimation
// @namespace    NoAnimation
// @version      0.1
// @description  try to take over the world!
// @author       You
// @include      *.imdb.com/search*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// @grant        GM_log
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_addStyle
// @grant        GM_openInTab
// @grant        GM_xmlhttpRequest
// @grant        GM_registerMenuCommand
// ==/UserScript==

$("lister-item mode-advanced")  .show ()
  .has ("span.genre:contains('Animation')")
  .hide ();

which doesn't work of course :(

I'm doing this test on akas.imdb.com/search/title?....

I hope I was clear enough. Can anyone give me advice? :)

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Daniele
  • 23
  • 2
  • Welcome to StackOverflow! It loooks like your code snippet is not correct due to class definition absence and test data. Please try digging a bit more about that and correct information in your question - it will help answer your question – Stepan Novikov Oct 19 '17 at 17:32
  • @StepanNovikov, For a Greasemonkey/Tampermonkey question, a link to a public target page is the gold-standard test data. – Brock Adams Oct 19 '17 at 18:19

1 Answers1

1

The main mistake is, that is not how to specify class in a jQuery selector. It should have been $(".lister-item.mode-advanced").

But there are other problems:

  1. Brittle selectors used. For example mode-advanced is not always present. May not always be a span, etc.
  2. Unnecessary logic (.show(), for example).
  3. Very obsolete version of jQuery.
  4. Extraneous and unhelpful meta info.

Here's a complete script that addresses these issues:

// ==UserScript==
// @name     Hide Animations from IMBD search results
// @match    *://*.imdb.com/search*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant    GM_addStyle
// ==/UserScript==
//- The @grant directive is needed to restore the proper sandbox.

$(".lister-item").has (".genre:contains('Animation')").hide ();
Brock Adams
  • 90,639
  • 22
  • 233
  • 295