从不重新启动(引导程序)的插件获取Thunderbird的电子邮件编辑器对象

时间:2016-09-11 21:23:23

标签: javascript xul thunderbird thunderbird-addon

我正在为Thunderbird创建一个无重启(bootstrap)插件,以复制我多年前制作的基于叠加的插件的功能。希望操纵新电子邮件正文中的一些文本。在the old overlay version中,它非常简单:我可以使用gMsgCompose对象。如何在无重新启动的插件中获取组合窗口的gMsgCompose对象?

这是我现在的代码。有一段时间我认为edElem几乎就是我想要的,这就是为什么我要测试转储edElem.editortype(当我确实拥有正确的对象时,它应该是“textmail”或“htmlmail”)。

    'use strict';

    const Cc = Components.classes;
    const Ci = Components.interfaces;
    const Cu = Components.utils;

    Cu.import("resource://gre/modules/Services.jsm");

    function startup(data, reason)
    {
        Services.wm.addListener(MyAddon.windowListener);
    }

    function shutdown(data, reason)
    {
        Services.wm.removeListener(MyAddon.windowListener);
    }

    function install(aData, aReason) { }
    function uninstall(aData, aReason) { }

    if(!MyAddon) var MyAddon = {};
    MyAddon.windowListener = {
        onOpenWindow: function(aXULWindow) {
            let aDOMWindow = aXULWindow
                .QueryInterface(Ci.nsIInterfaceRequestor)
                .getInterface(Ci.nsIDOMWindow);
            if (!aDOMWindow) return;

            aDOMWindow.addEventListener("load", function _cl_load(event){
                aDOMWindow.removeEventListener("load", _cl_load, false);
                MyAddon.handleOpenWindow(aDOMWindow, event.target);
            }, false);
        }
    }; // MyAddon.windowListener

    MyAddon.handleOpenWindow = function(aDOMWindow, DOMdocument) {
        if(DOMdocument.documentURI != "chrome://messenger/content/messengercompose/messengercompose.xul")
            return;
        let edWindow = DOMdocument.documentElement;
        // Just to be sure
        if(edWindow.id != 'msgcomposeWindow')
            return;

        let edElem = DOMdocument.getElementById("content-frame");

        /* I thought edElem was the element I want, but the following
         * returns an empty result, which I take to mean the element isn't
         * fully loaded yet.
         */
        dump("XXX handleOpenWindow: edElem.editortype="+edElem.editortype+"\n");

        /* Adding a listener to this element doesn't get the behaviour
         * I want either. I've tried hooking several events
         * in the following fashion, and the event handler code doesn't
         * execute for any of them, so maybe edElem isn't what I want.
         */
        [ "load",
          "unload",
          "compose-window-init",
          "compose-window-close",
          "compose-fields-ready",
          "compose-send-message",
        ].forEach(function(eventName) {
            edElem.addEventListener(eventName, function _eE_FIXME(event){
                dump("XXX "+eventName+": edElem.editortype="+edElem.editortype+"\n");
            }, false);
        });

        /* So, how do I get control of the editor,
         * so I can read and play with its content?
         */

    }; // MyAddon.handleOpenWindow

我在stackoverflow上发现的唯一问题就是Get sender and recipients in Thunderbird extension upon sending message。我已经尝试过他们在那里做的事情,但它似乎只是给我另一种方法来获得整个构图窗口,我已经可以得到它。

1 个答案:

答案 0 :(得分:0)

我在BEGIN { c=0;FS="[ \t]+";OFS=" ";x="";y=""; } c==2{ print x, 1, 20; print y; c=0; } NF ==2{ print $0; } NF>2 && NF<=5{ if(c==1){ print $0; y=$0;c=2;next; } if($2==11){ print $0, 1, 20; x=$0;c=1; } else print $0; } NF>5{ print $0,"hello"; } END{ if(c==2){ print x, 1, 20; print y; } }

中制作了一个带有计时器的丑陋存根
onOpenWindow

那么(在domWindow.setTimeout( function() { uploadHook( domWindow ); }, 500 ); 中)我可以得到编辑:

uploadHook

但寻找更好的解决方案。