首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的Greasemonkey脚本在更新后停止工作

我的Greasemonkey脚本在更新后停止工作
EN

Stack Overflow用户
提问于 2013-02-04 19:13:27
回答 1查看 892关注 0票数 1

我为StumbleUpon做了一个Greasemonkey脚本,它起了作用。但是突然之间,也许在Mozilla或Scriptish更新之后,它停止了所有协议的工作。

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

剧本:

代码语言:javascript
复制
// ==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 () );
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-04 23:26:45

使用Firefox 17,火狐放弃对E4X的支持。E4X允许我们使用(<><![CDATA[ ... ]]></>).toString ()构造来制作简单、健壮、多行的字符串。

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

代码语言:javascript
复制
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和script的未来版本。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14693806

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档