hoverIntent という jQuery プラグインが埋め込まれた単純な GreaseMonkey スクリプトを作成しています。(これは非常に小さなプラグインなので、ホストするのではなく埋め込みます。)
私の問題: プラグインがそのイベント ハンドラーを DOM オブジェクトにアタッチした後、イベントが「jQuery が定義されていません」というエラー メッセージをトリガーします。
範囲の問題ですか?ここに私のスクリプト全体があります:
if(unsafeWindow.console){
var GM_log = unsafeWindow.console.log;
}
(function($){
//HoverIntent
$.fn.hoverIntent=function(f,g){...};
//Removed the plugin code. You can see it in the link at the bottom
//of the post.
//DOM is ready
//Fetch all the rows with arrows
$('.arrow')
.each(function(){
$(this).hoverIntent(mouseOver,mouseOut);
});
//mouseOver
function mouseOver(){
//THIS IS WHERE THE ERROR HAPPENS
$(this).click();
}
//mouseOut
function mouseOut(){ //nothing here.
}
})(unsafeWindow.jQuery);
コピーして貼り付け、GM 固有のタグをすべて削除し、コンソールから実行すると正常に動作します。そして、これが私が埋め込んでいるプラグインです。