Firefox插件,刷新水龙头和自动重新发送数据 [英] Firefox addon which refreshes the tap and auto resend data

查看:158
本文介绍了Firefox插件,刷新水龙头和自动重新发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



首先,我将一个contentScript添加到一个标签页来获取一些信息在我的插件中的页面

$ $ p $ $ $ $ c $ tab.attach({
contentScript:self.port.emit ...

使用 $ b $进行刷新b

  tab.reload(); 

每次都会弹出一个提示如果它应该重发数据。

我想自动重发数据
我该怎么做?附加或在contentScript中?
是否与Load Flags常量有关?

解决方案

接受按钮,当你打开提示符时,你会看到几百毫秒的提示窗口。

我必须使用 setTimeout 有0等待时间,其他方式 aDOMWindow.args 属性和 aDOMWindo w.Dialog 和其他一些东西将是未定义或空奇怪。但这个工程:

  var stringBundle = Services.strings.createBundle('chrome://browser/locale/appstrings.properties' ); 

尝试{
windowListener.unregister();
} catch(ignore){}

var windowListener = {
//不要编辑$ b $ onOpenWindow:function(aXULWindow){
//等待窗口完成加载
让aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
aDOMWindow.addEventListener('load',function(){
aDOMWindow.removeEventListener('load',arguments.callee,false);
windowListener.loadIntoWindow(aDOMWindow,aXULWindow);
},false);

onCloseWindow:function(aXULWindow){},
onWindowTitleChange:function(aXULWindow,aNewTitle){},
register:function(){
//加载到任何现有的窗口
让XULWindows = Services.wm.getXULWindowEnumerator(null);
while(XULWindows.hasMoreElements()){
let aXULWindow = XULWindows.getNext();
让aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
windowListener.loadIntoWindow(aDOMWindow,aXULWindow);
}
//收听新窗口
Services.wm.addListener(windowListener);
},
unregister:function(){
//从任何现有窗口卸载
让XULWindows = Services.wm.getXULWindowEnumerator(null);
while(XULWindows.hasMoreElements()){
let aXULWindow = XULWindows.getNext();
让aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
windowListener.unloadFromWindow(aDOMWindow,aXULWindow);
}
//停止监听,以便将来添加的窗口不要得到这个连接
Services.wm.removeListener(windowListener);
},
// END - 不要编辑$ b $ loadIntoWindow:function(aDOMWindow,aXULWindow){
if(!aDOMWindow){
return;

if(aDOMWindow.location =='chrome://global/content/commonDialog.xul'){
var repostString = stringBundle.GetStringFromName('confirmRepostPrompt');
var repostStringFormatted = stringBundle.formatStringFromName('confirmRepostPrompt',[aDOMWindow.Application.name],1);
aDOMWindow.setTimeout(function(){
console.log('setimeout val 00:',aDOMWindow.args)
//aDOMWindow.args和aDWindWindow.Dialog直到setTimeout的0如此奇怪
if(aDOMWindow.args.text == repostString || aDOMWindow.args.text == repostStringFormatted){
console.log('这是重新发送提示所以接受它');
//aDOMWindow.Dialog.ui.button0.click(); //不工作
//aDOMWindow.Dialog.onButton0(); //不工作
//aDOMWindow.ondialogaccept() ; //不工作
var dialog = aDOMWindow.document.getElementById('commonDialog');
var btnAccept = aDOMWindow.document.getAnonymousElementByAttribute(dialog,'dlgtype','accept');
btnAccept.click();
console.log('clicked');
}
},0);


$ b unloadFromWindow函数(aDOMWindow,aXULWindow){
if(!aDOMWindow){
return;
}
}
};

windowListener.register();

打开便签簿。设置environemnt浏览器。运行代码。刷新页面以获得提示,您将看到它被点击。


I'm trying make a firefox add-on, which reloads a page automatically under some conditions.

First I add a contentScript to a tab to get some information on the page in my addon

tab.attach({
            contentScript:self.port.emit...

I have it working to the point of the refresh with

tab.reload();

but then an alert pops up every time "if it should resend data".

I want to resend the data automatically. How and where do I do it? In the add-on or in the contentScript? Has it to do with the Load Flags constant?

解决方案

This clicks the accept button when the prompt opens. But you see the prompt window for like a couple hundred ms.

i had to use setTimeout with 0 wait time other wise the aDOMWindow.args property and aDOMWindow.Dialog and a bunch of other stuff would be undefined or null so weird. But this works:

var stringBundle = Services.strings.createBundle('chrome://browser/locale/appstrings.properties');

try {
    windowListener.unregister();
} catch (ignore) {}

var windowListener = {
    //DO NOT EDIT HERE
    onOpenWindow: function(aXULWindow) {
        // Wait for the window to finish loading
        let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
        aDOMWindow.addEventListener('load', function() {
            aDOMWindow.removeEventListener('load', arguments.callee, false);
            windowListener.loadIntoWindow(aDOMWindow, aXULWindow);
        }, false);
    },
    onCloseWindow: function(aXULWindow) {},
    onWindowTitleChange: function(aXULWindow, aNewTitle) {},
    register: function() {
        // Load into any existing windows
        let XULWindows = Services.wm.getXULWindowEnumerator(null);
        while (XULWindows.hasMoreElements()) {
            let aXULWindow = XULWindows.getNext();
            let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
            windowListener.loadIntoWindow(aDOMWindow, aXULWindow);
        }
        // Listen to new windows
        Services.wm.addListener(windowListener);
    },
    unregister: function() {
        // Unload from any existing windows
        let XULWindows = Services.wm.getXULWindowEnumerator(null);
        while (XULWindows.hasMoreElements()) {
            let aXULWindow = XULWindows.getNext();
            let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
            windowListener.unloadFromWindow(aDOMWindow, aXULWindow);
        }
        //Stop listening so future added windows dont get this attached
        Services.wm.removeListener(windowListener);
    },
    //END - DO NOT EDIT HERE
    loadIntoWindow: function(aDOMWindow, aXULWindow) {
        if (!aDOMWindow) {
            return;
        }
        if (aDOMWindow.location == 'chrome://global/content/commonDialog.xul') {
            var repostString = stringBundle.GetStringFromName('confirmRepostPrompt');
            var repostStringFormatted = stringBundle.formatStringFromName('confirmRepostPrompt', [aDOMWindow.Application.name], 1);
            aDOMWindow.setTimeout(function() {
                console.log('setimeout val 00:', aDOMWindow.args)
                    //aDOMWindow.args and aDOMWindow.Dialog is not available till after setTimeout of 0 so weird
                if (aDOMWindow.args.text == repostString || aDOMWindow.args.text == repostStringFormatted) {
                    console.log('this is resend prompt so accept it');
                    //aDOMWindow.Dialog.ui.button0.click(); //doesnt work
                    //aDOMWindow.Dialog.onButton0(); // doesnt work
                    //aDOMWindow.ondialogaccept(); //doesnt work
                    var dialog = aDOMWindow.document.getElementById('commonDialog');
                    var btnAccept = aDOMWindow.document.getAnonymousElementByAttribute(dialog, 'dlgtype', 'accept');
                    btnAccept.click();
                    console.log('clicked');
                }
            }, 0);
        }

    },
    unloadFromWindow: function(aDOMWindow, aXULWindow) {
        if (!aDOMWindow) {
            return;
        }
    }
};

windowListener.register();

open scratchpad. set environemnt to browser. run the code. refresh a page to get prompt you'll see it get clicked.

这篇关于Firefox插件,刷新水龙头和自动重新发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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