setTimeout不适用于addon

时间:2012-07-06 16:42:59

标签: firefox-addon settimeout firefox-addon-sdk

我正在使用builder.addons.mozilla创建一个插件,我已在下面发布了main.js代码。我的想法是,当我单击插件的小部件时,它通过将disableWebIQ变量设置为true来禁用在panelist-webiq-cdn.appspot.com/warptest上运行的脚本。设置变量有效,但无论何时安装插件,页面脚本中的setTimeout调用都不起作用。是否向页面添加PageMod会禁用setTimeout?

按钮脚本和myScript.js的代码没有太大作用,并且当你单击小部件时myScript.js没有运行,所以我怀疑是什么在页面中禁用了setTimeout。

var ss = require("simple-storage");
ss.storage.enabled = true;
ss.storage.panelIdList = [];
const widgets = require("widget");
const data = require("self").data;

var player = widgets.Widget({
    id: "player",
    width: 16,
    label: "PanelistWebIQ",
    contentURL: data.url("buttons.html"),
    contentScriptFile: data.url("buttonScript.js"),
    onClick: function(){
        if(ss.storage.enabled){
            ss.storage.enabled = false;
            pageMod.destroy();
        }
        else{
            ss.storage.enabled = true;
            pageMod = pageModModule.PageMod({
                include: "*",
                contentScriptWhen: 'start',
                contentScriptFile: data.url('myScript.js')
            });
        }
    }
});

var pageModModule = require("page-mod");
var pageMod = pageModModule.PageMod({
    include: "*",
    contentScriptWhen: 'start',
    contentScriptFile: data.url('myScript.js'),
    onAttach: function(worker){
        var url = worker.url;
        var newPanelId = '';

        if(url.match(/^https?:\/\/panelist-webiq-cdn.appspot.com.*panelId=.*$/)){
            var pattern = 'panelId=';
            var index = url.indexOf(pattern);
            var sub = url.substring(index + pattern.length);
            index = sub.indexOf('&');
            if(index==-1){
                newPanelId = sub;
            }
            else{
                newPanelId = sub.substring(0, index);
            }
        }

        var list = ss.storage.panelIdList;
        if(newPanelId){
            var matchFound = false;
            for(var ctr=0; ctr<list.length; ctr++){
                var panelId = list[ctr];
                if(panelId==newPanelId){
                    matchFound = true;
                    break;
                }
            }
            if(!matchFound){
                list.push(newPanelId);
            }
        }
        worker.postMessage(list + '');
    }
});

1 个答案:

答案 0 :(得分:0)

显然,如果脚本中有警报,则该警报可以禁用将来对setTimeout的调用。我从我的插件中删除了所有提醒,但它运行正常。