在“下载文件”对话框中添加一个选项



我正试图为某个文件类型编写一个插件,我想在下载文件对话框的"打开"one_answers"保存文件"选项下添加一个"发送到MyAddonName"选项。不是指下载管理器。

使用Firefox Addon SDK有什么方法可以实现这一点吗?这是我的第一个扩展,所以我对SDK或更高级的XUL插件不是很熟悉。

我不知道如何使用addon-sdk来实现这一点。但这就是我从引导插件中实现的方式。

我会使用Services.wm.addEventListener来添加这个,并监听chrome://mozapps/content/downloads/unknownContentType.xul 的窗口加载

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);
        }, false);
    },
    onCloseWindow: function(aXULWindow) {},
    onWindowTitleChange: function(aXULWindow, aNewTitle) {},
    register: function() {
        // Load into any existing windows
        let DOMWindows = Services.wm.getEnumerator(null);
        while (DOMWindows.hasMoreElements()) {
            let aDOMWindow = DOMWindows.getNext();
            windowListener.loadIntoWindow(aDOMWindow);
        }
        // Listen to new windows
        Services.wm.addListener(windowListener);
        registered = true;
    },
    unregister: function() {
        // Unload from any existing windows
        let DOMWindows = Services.wm.getEnumerator(null);
        while (DOMWindows.hasMoreElements()) {
            let aDOMWindow = DOMWindows.getNext();
            windowListener.unloadFromWindow(aDOMWindow);
        }
        for (var u in unloaders) {
            unloaders[u]();
        }
        //Stop listening so future added windows dont get this attached
        Services.wm.removeListener(windowListener);
    },
    //END - DO NOT EDIT HERE
    loadIntoWindow: function(aDOMWindow) {
        if (!aDOMWindow) {
            return;
        }
        if (aDOMWindow.location == 'chrome://mozapps/content/downloads/unknownContentType.xul'); {
            //check file type
            var fileName = aDOMWindow.document.getElementById('location').value;
            var fileType = fileName.substr(fileName.lastIndexOf('.'));
            if (fileType == 'zip') {
                var myxul = document.createElementNS('xul namescpae here look it up', 'element you want');
                aDOMWindow.document.insertBefore(elementToInsertBefore, myXul);
            }
        }
    },
    unloadFromWindow: function(aDOMWindow) {
        if (!aDOMWindow) {
            return;
        }
    }
}
};

相关内容

  • 没有找到相关文章

最新更新