How to play nicely with jQuery and Greasemonkey
Overview
This is a simple snippet that helps us load the jQuery power into
our userscripts with Greasemonkey 0.7 or lower, newer versions may use @require
.
Updates
2010-04-24:
The userscript checks if jQuery is
already loaded in the page and uses it, otherwise loads it from Google's
CDN. It's also using jQuery.noConflict(true).
Thanks to everyone who sent me emails about this over this and last year.
Code
javascript:
var $;
// Add jQuery
(function(){
if (typeof unsafeWindow.jQuery == 'undefined') {
var GM_Head = document.getElementsByTagName('head')[0] || document.documentElement,
GM_JQ = document.createElement('script');
GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
GM_JQ.type = 'text/javascript';
GM_JQ.async = true;
GM_Head.insertBefore(GM_JQ, GM_Head.firstChild);
}
GM_wait();
})();
// Check if jQuery's loaded
function GM_wait() {
if (typeof unsafeWindow.jQuery == 'undefined') {
window.setTimeout(GM_wait, 100);
} else {
$ = unsafeWindow.jQuery.noConflict(true);
letsJQuery();
}
}
// All your GM code must be inside this function
function letsJQuery() {
alert($); // check if the dollar (jquery) function works
alert($().jquery); // check jQuery version
}
分享到:
相关推荐
greaseMonkey
greasemonkey-0-8-20090123-1-en-win-
Greasemonkey Hacks.chm
深入浅出 Greasemonkey优化
FIREFOX专用GreaseMonkey.xpi
Greasemonkey是Mozilla Firefox的一个附加组件。它让用户安装一些脚本使大部分HTML为主的网页于用户端直接改变得更方便易用。随着Greasemonkey脚本常驻于浏览器,每次随着目的网页打开而自动做修改,使得运行脚本的...
这本书、及其样例代码和视频文件都是自由软件。在“GNU 通用公共许可证(自由软件基金会)(版本2以及更新版本)”许可下,您可以随意的再分发和/或修改它们。我们发行这本书、及其样例代码和视频文件,希望它能对您有所...
不同网上普遍的无图、排版错误等,完美原版,请收下。 万恶的Baidu文库竟然要收1下载券,怒下分享之!
firefox插件greasemonkey-0.8.20080609.0-fx_PConline.xpi
greasemonkey-4.11.xpi
介绍 Firefox 经典插件 Greasemonkey 的书籍,市面上仅有的权威版本。 Greasemonkey is a Firefox extension that allows you to write scripts that alter the web pages you visit. You can use it to make a web...
莎拉的 Greasemonkey 脚本 这不适合公共消费。 查看、编辑、使用、讨论或共享在此存储库中找到的任何文件需要书面许可。 版权所有。
GreaseMonkey, Firefox 最强大的扩展之一,通过插入JS代码来改变当前网页内容. 此书为Greasemonkey官方发布开发手册
《深入浅出_Greasemonkey》pdf格式文档,自己添加了书签,查看指定的内容更方便
Greasemonkey / Tampermonkey脚本 这是我收集的GM脚本。 8首曲目隐藏专辑封面 该脚本将隐藏带有渐变的专辑封面。 我之所以开发此功能,是因为我听的某些曲目的专辑封面在工作环境(NSFW)中可能令人反感。 亚马逊每...
请注意,不能保证XPI安装将在公告的minVersion和maxVersion中运行。 Farby确实包含了SeaMonkey的一些基础知识,但是似乎缺少了一些东西。... https://openuserjs.org/announcements/Greasemonkey_Port_Update上的公告
深入浅出Greasemonkey,油猴脚本入门
-军阀TW扩展Sangu软件包是适用于Firefox,Opera和Chrome的Greasemonkey脚本,可通过在几乎每个页面(尤其是村庄概览页面)上添加额外功能来提高《游戏速度并优化游戏流程。 在可用,或与安装。支持Sangu软件包支持...
一个非常好的消息是,现在Chrome 最新的4.0版本已经支持GreaseMonkey脚本了,当然 chrome 5.0 dev版本也支持它
HJJ目录页突出最近发布帖子的脚本,用于Firefox的greasemonkey扩展