1

我在 GM 1.5 中使用 jQuery,发现我无法使用 .get

我需要http://code.jquery.com/jquery.js

我的代码就是这样

this.$ = this.jQuery = jQuery.noConflict(true);

$(document).ready(function () {
    $.get('index.php',function () {
        console.log('yay');
        console.log($(this).html());

    });
});

我确定我在以前的版本中能够做到这一点,这与所做的沙箱更改有关吗?

4

1 回答 1

1

问题中的代码工作正常。在 Windows XP 和 Windows 7 上使用 Greasemonkey 1.5 和 Firefox 16 和 17 进行了验证。

关于:

啊,现在我被告知 GM_setValue 不存在。我不认为这是 GM_ 功能和 jQuery 功能之间的选择


  1. 你不必选择。不要注入 jQuery(或大多数其他库)使用@require. 然后,通过适当的@grant指令,您可以GM_轻松地使用函数。

  2. this.$ = this.jQuery = jQuery.noConflict(true);除非您使用@grant none-- 这会关闭GM_功能,否则代码中没有任何意义。

  3. $(document).ready()Greasemonkey 脚本中不需要,除非您使用@run-at document-start.


所以,使用这样的代码:

// ==UserScript==
// @name     YOUR_SCRIPT_NAME
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant    GM_getValue
// @grant    GM_setValue
// @grant    etc., etc.
// ==/UserScript==

$.get ('index.php', function () {
    console.log ('yay');
    console.log ($(this).html () );
} );
于 2012-11-23T17:53:56.480 回答