1

I had made a Greasemonkey script for StumbleUpon, and it worked. But suddenly, maybe after a Mozilla or Scriptish update, it stopped working on all protocols.

Please review my script for a mistake. I am a novice in scripting

Script:

// ==UserScript==
// @name            [udit]add stumblethru image-flip button[w/o container] on all websites
// @namespace       testing-for-that-script
// @description     
// @include         http://facebook.com/*
// @include         http://*
// @include         https://*
// @include         *
// @exclude         file:///*
// ==/UserScript==

if (window.top != window.self)  //don't run on frames or iframes
{
    //Optional: GM_log ('In frame');
    return;
}

/*--- Create a button in a container div.  It will be styled and positioned with CSS.
*/
var zNode       = document.createElement ('input');
zNode.setAttribute ('id', 'suButton');
zNode.setAttribute( 'type', 'image' );
zNode.setAttribute( 'src', 'http://www.creativeadornments.com/nephco/doraemon/icons/doraemon_18a.gif' );
document.body.appendChild (zNode);

function tiddu1()
{
document.getElementById("suButton").src ="http://www.creativeadornments.com/nephco/doraemon/icons/doraemon_07.gif";
}

function tiddu2()
{
document.getElementById("suButton").src ="http://www.creativeadornments.com/nephco/doraemon/icons/doraemon_18a.gif";
}

function tiddu3()
{
document.getElementById("suButton").src ="http://www.creativeadornments.com/nephco/doraemon/icons/dorami_01a.gif";
}

function tiddu4()
{
document.getElementById("suButton").src ="http://t1.gstatic.com/images?q=tbn:ANd9GcSI_hx0nLvnO-Em6elAxyMnoBFGw8IMD3Yrpep4XY2I51GylSRf3jHiabAyiw";
}

//--- Activate the newly added button and add rollover image handling.
var zNode = document.getElementById ("suButton");
zNode.addEventListener ("click",        ButtonClickAction,  true);
zNode.addEventListener ("mouseover",    tiddu1,          true);
zNode.addEventListener ("mouseout",     tiddu2,           true);
zNode.addEventListener ("mousedown",     tiddu3,           true);
zNode.addEventListener ("click",     tiddu4,           true);

function ButtonClickAction (zEvent)
{
    //--- For our dummy action, we'll just add a line of text to the top of the screen.
    var button  = document.createElement ('a');
    location.href='http://www.stumbleupon.com/to/stumble/stumblethru:'+location.href.replace("http://","").replace("https://","").replace("ftp://","").split('/',4)[0];
}

//--- Style our newly added elements using CSS.
GM_addStyle ( (<><![CDATA[
    #suButton {
        position:               fixed;
        bottom:                 0px;
        left:                   0px;
        margin:                 0px 0px 50px 0px;
        opacity:                0.8;
        cursor:                 url(C:\buttercup_06.cur),url(http://www.creativeadornments.com/nephco/powerpuffgirls/cursors/ppg_01anim.gif),url(myBall.cur),pointer;
        border:                 0px outset red;
        z-index:                222;
        padding:                5px 5px;
    }
]]></>).toString () );
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
adi
  • 207
  • 1
  • 10

1 Answers1

1

With Firefox version 17, Firefox dropped support for E4X. E4X is what allowed us to use that (<><![CDATA[ ... ]]></>).toString () construct to make easy, robust, multi-line strings.

Now that E4X is no longer supported, we must refactor every bit of code that used CDATA, to use the javascript string escape (\). So you need to change that GM_addStyle call to:

GM_addStyle ( "                                             \
    #suButton {                                             \
        position:       fixed;                              \
        bottom:         0px;                                \
        left:           0px;                                \
        margin:         0px 0px 50px 0px;                   \
        opacity:        0.8;                                \
        cursor:         url(C:\buttercup_06.cur),url(http://www.creativeadornments.com/nephco/powerpuffgirls/cursors/ppg_01anim.gif),url(myBall.cur),pointer; \
        border:         0px outset red;                     \
        z-index:        222;                                \
        padding:        5px 5px;                            \
    }                                                       \
" );


Taking care with how you mix ' and " quotes.



Also, since you are using GM_addStyle, add // @grant GM_addStyle to your script's metadata block so that the script continues to work with future versions of Greasemonkey and Scriptish.

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • that was most helpful and working buddy ! a great relax . there is a little bit of a problem in same sort of script , i try to modify it according to the solution but it ain't work . that bit of script is n next comment , please review .sorry for my bad english skills or site ettiquete that u have to edit my question . – adi Feb 05 '13 at 04:47
  • i couldn't put the bit of script in comment , so i updated/edited the question to insert that script. – adi Feb 05 '13 at 04:58
  • 1
    As a courtesy, and to avoid confusion, whenever an answer works for the question as asked, but you have a new wrinkle that wasn't covered in the original question, for which the answer doesn't work, ask it in a comment (if it's trivial enough) or open a new question and link back to the original. In this case, linking to a pastebin (from your comment) would have been enough, but editing the question is a little confusing. All that said... ... – Brock Adams Feb 05 '13 at 06:20
  • 1
    Refer to the bit about `Taking care with how you mix ' and " quotes`. The whole `GM_addStyle` call is wrapped in double-quotes (`"`), but double-quotes are used again inside the string! To fix this, change all internal, double-quotes to single quotes. So, in this case, `"Times New Roman"` should be changed to `'Times New Roman'`. – Brock Adams Feb 05 '13 at 06:20