Frage

Update: The OP now confirms that the problem occurred due to Greasemonkey being disabled.


I am trying to make a simple Greasemonkey script, however it doesn't appear to do anything and nothing relevant appears in the console.

The script:

// ==UserScript==
// @name        test
// @namespace   test
// @description testing script (jquery)
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js
// @include *
// @version     1
// @grant       none
// ==/UserScript==

$(document).ready(function() {
alert("hello");
 GM_log("hello, greasemonkey here");});

I have tried it without the $(document).ready and jquery, however it still does not work.

War es hilfreich?

Lösung

With @grant none you cannot use any of the Greasemonkey functions such as GM_log, GM_addStyle, etc.

The reason why it fails is that using the GM_ functions require the sandbox to be enabled -- @grant none disables this sandbox to allow code to run as it would on an ordinary page.

Instead of using GM_log (which is deprecated), you should use console.log instead.

Note that when you're running Greasemonkey code that errors only go to the browser console (or Firebug if you've enabled chrome logging) -- you can access the browser console by pressing Ctrl + Shift + J on Windows, and Cmd + Opt + J.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top