문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top