问题中的代码工作正常。在 Windows XP 和 Windows 7 上使用 Greasemonkey 1.5 和 Firefox 16 和 17 进行了验证。
关于:
啊,现在我被告知 GM_setValue 不存在。我不认为这是 GM_ 功能和 jQuery 功能之间的选择
你不必选择。不要注入 jQuery(或大多数其他库)使用@require
. 然后,通过适当的@grant
指令,您可以GM_
轻松地使用函数。
this.$ = this.jQuery = jQuery.noConflict(true);
除非您使用@grant none
-- 这会关闭GM_
功能,否则代码中没有任何意义。
$(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 () );
} );