Search code examples
jquerygreasemonkeyscriptish

Can someone tell me why this jQuery/Javascript script isn't working?


I am trying to create a script that automatically votes a photo for a contest when I load the page (no illicit stuff, I can vote once per day :D).

The script is as follows:

window.onload = function() {

  var jq = document.createElement('script');
  jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
  document.getElementsByTagName('head')[0].appendChild(jq);

  console.log("Enters here");


  $link = $('.photo_vote'); 
  $link[0].click();
  console.log("Enters here too");
}

If i run this script on the Mozilla console, it works perfectly. However, if I try to autorun it using greasemonkey or scriptish, it doesn't click on the vote button. Also the second echo isn't printed either.

Can someone help me with that?


Solution

  • You should include jQuery directly into the Greasemonkey @require container - I don't think you can run that code directly in the GM sandbox. http://wiki.greasespot.net/Third-Party_Libraries