Search code examples
javascriptjquerygreasemonkeytampermonkey

Code works in console/scratchpad but not in a Greasemonkey script?


I'm trying to write a script to make the map larger on Google Flights.

I've got the jQuery working in the Firefox scratchpad. This script does exactly what I am trying to accomplish:

$('div').filter(function(){ 
   return $(this).css('width') == '648px'
}).css({"width":"900px","height":"550px"});

but when I paste that into a Greasemonkey script, it doesn't work. If I add some console.logs to debug, I can verify that the script is running and the filter is working correctly, but it's not modifying the CSS. Any ideas?


Solution

  • Sometime you will need to make sure the script is executed after that the page was loaded

    $(function(){
       // YOUR CODE HERE
    });
    

    You can also try with setTimeout and put 2sec (2000)

    var myfunc = function(){
      // YOUR CODE HERE
    };
    setTimeout(myfunc, 2000);