7

This news site (The Guardian) has a small frame that displays in the bottom-right of the page, with code like this:

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

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

</div>

I hid the internal contents of the inner div because they're not important. I wrote a Greasemonkey script that uses JQuery to hide this box because it appears on every page:

// ==UserScript==
// @name        hide-guardian-ad
// @namespace   guardian
// @description Hides the Guardian social media frame
// @version     1
// @grant       none
// ==/UserScript==

// @require       http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js

$(".social-cta-overlay").hide()

I installed the script, but nothing happens and the box is still there.

Jacob
  • 73
  • 1
  • 1
  • 3

2 Answers2

14

That script has 3 problems (worst first):

  1. The @require directive is outside the metadata block. This means that Greasemonkey ignores it as just an ordinary javascript comment.
  2. There is no @include or @match directive. This means that the script will fire on every page and iframe of every site! (Crashing some of them, and chewing up resources.)
  3. @grant none means that the script will interfere with and crash all or part of many sites.

This script works:

// ==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()
Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • 1
    Excellent, thank you. I presume `GM_addStyle` does exactly what it sounds like: gives the script permission to add styles *only*? (I couldn't find that specific option in [the documentation](http://wiki.greasespot.net/@grant)). – Jacob Feb 26 '14 at 15:51
  • 1
    Yes. Here is [the doc for `GM_addStyle`](http://wiki.greasespot.net/GM_addStyle). It's harmless to grant it in almost all cases, and doing so switches the sandbox back on. – Brock Adams Feb 26 '14 at 19:49
  • Isn't there supposed to be a semicolon at the end? This doesn't work for me, for the top banner of theguardian.com, anyway :/ I've not found any way to get rid of it. – paradroid Apr 29 '16 at 10:02
0

try this:

$(document).find(".social-cta-overlay").hide();
Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
  • 2
    As you can see from the other answer this is incorrect, since my script had quite a few problems. – Jacob Feb 26 '14 at 15:52