0

I'm trying to include cluetip in my GreaseMonkey script. To do this I've defined my userscript as follows:

// ==UserScript==
// @name           myscript
// @namespace      myscript
// @description    This is my script
// @require        http://plugins.learningjquery.com/cluetip/jquery.cluetip.js
// @require        http://plugins.learningjquery.com/cluetip/jquery.bgiframe.min.js
// @require        http://plugins.learningjquery.com/cluetip/jquery.hoverIntent.js
// @resource       jquery.cluetip.css http://plugins.learningjquery.com/cluetip/jquery.cluetip.css
// @include        http://mysite.com/*
// ==/UserScript==

(function(){
    function GM_init() {
        if(typeof unsafeWindow.jQuery == 'undefined') {
            window.setTimeout(GM_wait,100);
        } else {
            jQuery_init(unsafeWindow.jQuery);
        }
    }

    GM_init();

    function jQuery_init($) {
        $('a.testTitle').cluetip({splitTitle: '|'});
    }
})();

When I import the script it seems to import fine and my config.xml ends up with this entry:

<Script filename="myscript.user.js" name="myscript namespace="myscript" description="This is my script" enabled="true" basedir="myscript">
    <Include>http://mysite.com/*</Include>
    <Require filename="jquerycluetip.js"/>
    <Require filename="jquerybgiframemin.js"/>
    <Require filename="jqueryhoverintent.js"/>
    <Resource name="jquery.cluetip.css" filename="jquerycluetip.css" mimetype="text/css"/>
</Script>

After the script is installed I see the referenced requires and resources have been downloaded and renamed as per the entries in the myscript folder.

When I load the page myscript does not run. I've tried restarting Firefox, uninstalling and reinstalling the script and setting alerts to ensure the script isn't running. I'm at a loss as to what's wrong. Does anybody have a solution?

For information, JQuery is already included in the page, so I don't need to require it. If I remove all the cluetip entries from config.xml, remove the function call, restart Firefox and just try modifying the link with standard JQuery everything works fine.

Note: I tried adding JQuery to the @Require list as well. This means my script loads, but fails on the first cluetip function call.

Rich Seller
  • 83,208
  • 23
  • 172
  • 177
  • Can you post the script to http://userscripts.org/ or somewhere else and let us know what website this is for? I would like to debug it myself, but I am too lazy to do all the work. I have written quite a number of complex GM scripts in the past, but it has been a while. – Jason Bunting Sep 27 '09 at 16:31
  • it's actually for a GM script for SO. I posted an explanation and a link to the current version, using my workaround, on meta (http://meta.stackexchange.com/questions/23656/greasemonkey-script-to-gold-plate-sofu) – Rich Seller Sep 27 '09 at 21:13
  • I modified your SO script to use this method, and it still seemed to work OK for me. I simply removed the @require and added the GM_init code at the top. Then I renamed the anonymous init function to jQuery_init($) and removed the surrounding $(...)() – Sam Brightman Mar 31 '10 at 15:07

1 Answers1

0

I found that it works if I import JQuery rather than using the GM_init approach AND remove all the GM_init code:

// ==UserScript==
// @name           myscript
// @namespace      myscript
// @description    This is my script
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// @require        http://plugins.learningjquery.com/cluetip/jquery.cluetip.js
// @require        http://plugins.learningjquery.com/cluetip/jquery.bgiframe.min.js
// @require        http://plugins.learningjquery.com/cluetip/jquery.hoverIntent.js
// @resource       jquery.cluetip.css http://plugins.learningjquery.com/cluetip/jquery.cluetip.css
// @include        http://mysite.com/*
// ==/UserScript==

$(function() {
    $('a.testTitle').cluetip({splitTitle: '|'});
})();

I would prefer to avoid making this change and continue to use the GM_init approach. But at least I have a workaround.

Rich Seller
  • 83,208
  • 23
  • 172
  • 177