jquery和greasemonkey齐上阵

jquery写起来真的很简单,连我这刚接触jquery不久的新人都能很快用它码出大段的javascript。唯一的坏处是代码里充斥了大量的$。既然写javascript如此简单,那么用jquery+greasemonkey插件同时干活怎么样呢?

这里是一段提醒jquery已经载入的脚本,为了避免和页面上原有的代码冲突,得运行$.noConflict().

// All your GM code must be inside this function
function letsJQuery() {
//make sure there is no conflict between jQuery and other libraries
$.noConflict()
//notify that jQuery is running...
  $('<div>jQuery is running!</div>')
	.css({padding: '10px', background: '#ffc', position: 'absolute',top: '0', width: '100%'})
	.prependTo('body')
	.fadeIn('fast')
	.animate({opacity: 1.0}, 300)
	.fadeOut('fast', function() {
	  $(this).remove();
	});
//start custom jQuery scripting.
}

引入jquery.js只用简单的一行,感谢greasemonkey!

GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';

载入jquery的脚本

var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://code.jquery.com/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);

原文:Have Your jQuery Fun on Any Site with Greasemonkey

作者: 发表于July 4, 2007 at 6:27 am

版权信息: 可以任意转载, 转载时请务必以超链接形式标明文章原始出处作者信息及此声明

Tags: ,,

4 条评论 »

  1. 肥大 于 2007-08-17 @ 20:52:07 留言

    推荐一款让Eclipse支持jquery的插件
    http://www.langtags.com/jquerywtp/index.html

  2. 六六 于 2007-09-24 @ 14:29:32 留言

    楼上的网站是抄袭人家http://www.java2s.com 的内容,
    想要看好东东,直接去www.java2s.com 就好了

  3. volcano 于 2007-09-24 @ 17:26:09 留言

    六六推荐的站点貌似有些参考价值

  4. 六六 于 2007-09-27 @ 12:11:54 留言

    当然,WWW.JAVA2S.COM 是个人最喜欢的代码网站

RSS 为此帖反馈评论 · 反向跟踪 网站

留条评论