【发布时间】:2011-11-21 21:58:45
【问题描述】:
从之前的SO post 我发现为了让 Greasemonkey 脚本与 Chrome 兼容,我们必须为 jQuery http://erikvold.com/blog/index.cfm/2010/6/14/using-jquery-with-a-user-script 创建脚本元素
如果我当前在 Firefox 中运行良好的用户脚本如下所示。我应该如何修改它以包含上述方法并仍然在 onload 时调用该函数?在之前的帖子中建议的解决方案中,我应该将当前代码放在哪里?
// ==UserScript==
// @name Google+
// @version 1.1
//
//
// @include http://plus.google.com/*
// @include https://plus.google.com/*
//
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
$(function()
{
$(window).bind('load', function()
{
console.log("Hi Condition is very bad!")
$('<div id="vdiv"></div>').prependTo('#contentPane');
$('<img>',
{
src: 'http://icons.iconarchive.com/icons/aha-soft/security/16/key-icon.png',
alt: 'Key',
title:'Key',
click: function(){
alert($(this).attr('title'));
var vtext = jQuery('div.f-ba-mg iframe').contents().find('body').text().trim();
alert(vtext);
}
})
.css({
cursor: 'pointer',
border: '1px solid black',
backgroundColor: 'white'
})
.appendTo('#vdiv');
});
});
【问题讨论】:
标签: jquery google-chrome greasemonkey