1

The below script works in Firefox/Greasemonkey, but nothing happens in Chrome/Tampermonkey.

Can anyone see why it doesn't work in Tampermonkey?

// ==UserScript==
// @name        Example
// @namespace   Example.com
// @description Example.com
// @include     https://example.com/*
// @include     http://example.com/*
// @version     1
// @grant       none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @require https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012
// ==/UserScript==

window.onload = function(){
  document.getElementById('close-cookies').click();
};

waitForKeyElements('div.survey16', removeSurvey);

function removeSurvey() {
  document.getElementById('survey16').hide();
}

$('.chat-bot').hide();
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Jasmine Lognnes
  • 6,597
  • 9
  • 38
  • 58

1 Answers1

2

The question code should not work in either browser and you should see error messages in the consoles.

Problems:

  1. document.getElementById('survey16') does not have a .hide() method. That's a jQuery function.
  2. removeSurvey() should be:

    function removeSurvey (jNode) {
        jNode.hide ();  //-- .hide is a jQuery function.
    }
    
  3. EXCEPT, there is a mismatch between the waitForKeyElements call and removeSurvey.
    In the first you are searching for a div with class survey16, but in the second you are trying to delete an element with the id survey16. Which is it?
  4. As a general rule, don't use @grant none when also using @require, this usually leads to page conflicts and crashes. jQuery is especially bad.
  5. Also, @grant none functions slightly differently in both browsers. When using @require, specify @grant GM_addStyle except in special, and rare, cases.
Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • Awesome! Do you know of a way to debug what `jNode` contains? I don't suppose you use `console.log` for this? – Jasmine Lognnes Nov 30 '16 at 13:39
  • 1
    jNode is always a standard [jQuery object](http://learn.jquery.com/using-jquery-core/jquery-object/). And, yes, you can console.log it. – Brock Adams Nov 30 '16 at 16:56