更新后,我的Greasemonkey脚本停止工作 [英] My Greasemonkey script stopped working after something updated

查看:205
本文介绍了更新后,我的Greasemonkey脚本停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



请检阅我的脚本。我是脚本编程的新手。

脚本:

$ $ p $ // = = UserScript ==
// @name [udit]在所有网站上添加stumblethru图像翻转按钮[w / o容器]
// @namespace测试这个脚本
/ / @description
// @include http://facebook.com/*
// @include http:// *
// @include https:// *
// @include *
// @exclude file:/// *
// == / UserScript ==

if(window.top!= window.self) //不要在框架或iframe上运行
{
//可选:GM_log('In frame');
return;
}

/ * ---在容器div中创建一个按钮。它将被样式化和定位与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);

函数tiddu1()
{
document.getElementById(suButton)。src =http://www.creativeadornments.com/nephco/doraemon/icons/doraemon_07 .gif注意;


函数tiddu2()
{
document.getElementById(suButton)。src =http://www.creativeadornments.com/nephco/叮当/图标/ doraemon_18a.gif;


函数tiddu3()
{
document.getElementById(suButton)。src =http://www.creativeadornments.com/nephco/叮当/图标/ dorami_01a.gif;


函数tiddu4()
{
document.getElementById(suButton)。src =http://t1.gstatic.com/images? q = TBN:ANd9GcSI_hx0nLvnO-Em6elAxyMnoBFGw8IMD3Yrpep4XY2I51GylSRf3jHiabAyiw;
}

// ---激活新添加的按钮并添加翻转图像处理。
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);

函数ButtonClickAction(zEvent)
{
// ---对于我们的虚拟操作,我们只需要在屏幕顶部添加一行文本即可。
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];
}

// ---使用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/指针;
border:0px outset red;
z-index:222;
padding:5px 5px;
}
]]>< />)。toString());


解决方案

使用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),指针; \
border:0px outset red; \
z-index:222; \
padding:5px 5px; \
} \
);



注意如何混合'引号。







此外,由于您正在使用 GM_addStyle ,请添加 // @grant GM_addStyle 添加到脚本的元数据块中,以便脚本可以继续使用未来版本的Greasemonkey和Scriptish。 p>

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 () );

解决方案

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.

这篇关于更新后,我的Greasemonkey脚本停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆