Hi,
i wrote i simple userscript to include some buttons at the top of each
website using JQuery.
The Problem is that my script throws errors on every site which
already uses JQuery. On sites which dont use JQuery, everything works
fine.
If i look into firebug i can see that my link to JQuery is not
included on sites which already include JQuery.
So this is a very fundamental question using Greasemonkey.
What can i do with sites that already use frameworks i also use inside
my userscript?
Here is also the code of my userscript:
// include jquery, ui etc.
(function(){
//if there are embedded frames - execute the script only on the top
frame
if (window.top !== window.self) {
return;
}
if (typeof unsafeWindow.jQuery == 'undefined') {
var GM_Head = document.getElementsByTagName('head')[0] ||
document.documentElement,
//jquery
GM_JQ = document.createElement('script');
GM_JQ.src = 'http://code.jquery.com/jquery-latest.pack.js';
GM_JQ.type = 'text/javascript';
GM_JQ.async = false;
//jquery ui
GM_JQUI_CORE = document.createElement('script');
GM_JQUI_CORE.src = 'http://jqueryui.com/ui/jquery.ui.core.js';
GM_JQUI_CORE.type = 'text/javascript';
GM_JQUI_CORE.async = false;
GM_JQUI_WIDGET = document.createElement('script');
GM_JQUI_WIDGET.src =
'http://jqueryui.com/ui/jquery.ui.widget.js';
GM_JQUI_WIDGET.type = 'text/javascript';
GM_JQUI_WIDGET.async = false;
GM_JQUI_BUTTON = document.createElement('script');
GM_JQUI_BUTTON.src =
'http://jqueryui.com/ui/jquery.ui.button.js';
GM_JQUI_BUTTON.type = 'text/javascript';
GM_JQUI_BUTTON.async = false;
//insert in head
GM_Head.insertBefore(GM_JQ, GM_Head.firstChild);
GM_Head.insertBefore(GM_JQUI_CORE, GM_Head.firstChild);
GM_Head.insertBefore(GM_JQUI_WIDGET, GM_Head.firstChild);
GM_Head.insertBefore(GM_JQUI_BUTTON, GM_Head.firstChild);
}
GM_wait();
})();
// Check if jQuery's loaded and ready
function GM_wait() {
if (typeof unsafeWindow.jQuery == 'undefined') {
window.setTimeout(GM_wait, 100);
} else {
jQuery = unsafeWindow.jQuery;//.noConflict(); - leads to
conflicts ;)
jQuery(document).ready(function() {
letsJQuery();
});
}
}
//----------------------------------------------------------------------
// Main function
//----------------------------------------------------------------------
function letsJQuery() {
function test() {
alert("yippie");
}
jQuery("<div><button name=\"button1\" id=\"button1\">A button
element</button><button>Another button element</button></div>")
.css({padding: '10px', background: '#ffc', position:
'fixed',top:
'0', left: '0', 'z-index': '66', width: '99%'})
.appendTo('body')
.fadeIn('fast')
.animate({opacity: 1.0}, 1000);
var button1 = document.getElementById('button1');
jQuery(button1).button();
jQuery(button1).click(test);
}
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/greasemonkey-users?hl=en.