如何使用Greasemonkey和Jquery隐藏具有特定类的HTML元素?

如何使用Greasemonkey和Jquery隐藏具有特定类的HTML元素?,jquery,greasemonkey,Jquery,Greasemonkey,这(监护人)有一个小框架,显示在页面的右下角,代码如下: <div class="initially-off social-cta-overlay"> <div class="social-cta-overlay-content"></div> </div> 我安装了脚本,但什么也没发生,盒子还在那里 试试这个: $(document).find(".social-cta-overlay").hide(); 该脚本有3个问题(最坏的

这(监护人)有一个小框架,显示在页面的右下角,代码如下:

<div class="initially-off social-cta-overlay">

    <div class="social-cta-overlay-content"></div>

</div>
我安装了脚本,但什么也没发生,盒子还在那里

试试这个:

$(document).find(".social-cta-overlay").hide();

该脚本有3个问题(最坏的一个):

  • @require
    指令在外部。这意味着Greasemonkey将其作为普通javascript注释忽略
  • 没有
    @include
    @match
    指令。这意味着脚本将在每个站点的每个页面和iframe上启动!(摧毁了其中一些,并吞噬了资源。)
  • @grant none
    的意思是
  • 这个脚本的工作原理是:

    // ==UserScript==
    // @name        hide-guardian-ad
    // @include     http://www.theguardian.com/*
    // @description Hides the Guardian social media frame
    // @require     http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
    // @grant       GM_addStyle
    // ==/UserScript==
    
    $(".social-cta-overlay").hide()
    

    太好了,谢谢。我想GM_addStyle确实是这样做的:只给脚本添加样式的权限?(我在中找不到该特定选项)。是。这是。在几乎所有情况下授予它都是无害的,这样做会重新打开沙箱。难道结尾不应该有分号吗?无论如何,对于卫报网站的头条来说,这对我来说不起作用:/我还没有找到任何方法来摆脱它。正如你从另一个答案中看到的,这是不正确的,因为我的脚本有很多问题。
    // ==UserScript==
    // @name        hide-guardian-ad
    // @include     http://www.theguardian.com/*
    // @description Hides the Guardian social media frame
    // @require     http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
    // @grant       GM_addStyle
    // ==/UserScript==
    
    $(".social-cta-overlay").hide()