1

我为StumbleUpon制作了一个 Greasemonkey 脚本,并且成功了。但突然间,也许在 Mozilla 或 Scriptish 更新之后,它停止了所有协议的工作。

请检查我的脚本是否有错误。我是脚本新手

脚本:

// ==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 () );
4

1 回答 1

1

在 Firefox 版本 17 中,Firefox 放弃了对 E4X 的支持。E4X 使我们能够使用该(<><![CDATA[ ... ]]></>).toString ()结构来制作简单、健壮的多行字符串。

现在不再支持 E4X,我们必须重构使用的每一段代码CDATA,以使用 javascript 字符串转义 ( \)。因此,您需要将该GM_addStyle调用更改为:

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;                            \
    }                                                       \
" );


注意你如何混合'"引用。



此外,由于您使用的是GM_addStyle,请添加// @grant GM_addStyle到脚本的元数据块中,以便脚本继续与 Greasemonkey 和 Scriptish 的未来版本一起使用。

于 2013-02-04T23:26:45.597 回答