【问题标题】:Hiding a div on IMDB search在 IMDB 搜索中隐藏 div
【发布时间】:2018-03-31 19:28:24
【问题描述】:

由于 IMDB 搜索无法排除特定类型,我想使用 Tampermonkey 或 Greasemonkey 隐藏我不感兴趣的类型。

每部电影都在一个名为 "lister-item mode-advanced" 的类中:

里面是:

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

查看其他答案,我认为这样的方法可以工作:

// ==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 ();

这当然行不通:(

我正在 akas.imdb.com/search/title?... 上做这个测试。

我希望我已经足够清楚了。谁能给我建议? :)

【问题讨论】:

  • 欢迎来到 StackOverflow!由于缺少类定义和测试数据,您的代码 sn-p 看起来不正确。请尝试在您的问题中挖掘更多相关信息并纠正信息 - 这将有助于回答您的问题
  • @StepanNovikov,对于 Greasemonkey/Tampermonkey 问题,指向公共目标页面的链接是黄金标准测试数据。

标签: greasemonkey tampermonkey imdb


【解决方案1】:

主要的错误是,这不是如何在 jQuery 选择器中指定类。应该是$(".lister-item.mode-advanced")

但还有其他问题:

  1. 使用了脆弱的选择器。例如mode-advanced 并不总是存在。可能并不总是跨度等。
  2. 不必要的逻辑(例如.show())。
  3. 非常过时的 jQuery 版本。
  4. 无关的和无用的元信息。

这是解决这些问题的完整脚本:

// ==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 ();

【讨论】:

  • 这完美地解决了我的求助请求!感谢您的宝贵时间。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-25
  • 2022-07-21
相关资源
最近更新 更多