【发布时间】:2014-09-18 10:14:21
【问题描述】:
我正在开发一个 Thunderbird 扩展。我想在主窗口中获取邮件项目内容并撰写邮件窗口。我该如何实现呢?
问候 三重
【问题讨论】:
标签: javascript thunderbird thunderbird-addon
我正在开发一个 Thunderbird 扩展。我想在主窗口中获取邮件项目内容并撰写邮件窗口。我该如何实现呢?
问候 三重
【问题讨论】:
标签: javascript thunderbird thunderbird-addon
如果您对如何在其中一个 Thunderbird 窗口中完成某项操作感兴趣,了解它是如何在 XUL DOM 中实现的方法是安装 [add-on][2] [DOM Inspector][3 ] 并使用它来调查 DOM 的内容是什么样的。您可能还需要 [Element Inspector][4] 附加组件,它是 DOM Inspector 的一个非常有用的补充(shift-right-click 将 DOM Inspector 打开到单击的元素)。您可能还会发现 [Stacked Inspector][5] 很有帮助。
要做的另一件事是找到一个扩展程序,该扩展程序在您想要工作的同一一般区域中执行某些操作。然后下载那个扩展,看看他们是如何做你感兴趣的事情的。
您的问题没有提供足够的信息,无法为您提供准确、详细的答复。我们需要知道您正在运行的环境。正在运行的脚本是否作为 UI 事件的一部分从主窗口启动?来自撰写窗口的 UI 事件?
如果脚本是从撰写窗口中的 UI 事件启动的,您可以通过以下方式访问消息内容:
let editor = document.getElementById("content-frame");
let editorDocument = editor.contentDocument;
let messageBody = editorDocument.getElementsByTagName("body")[0];
这应该可以,但我还没有验证:
let messageBody = document.getElementById("content-frame").contentDocument.body;
关于主窗口:消息内容位于<browser id="messagepane"> 元素中。拥有标签后,您应该能够从那里找到<browser>。
在 Firefox 中,您可以找到 <browser> 元素:
//Create some common variables if they do not exist.
// This should work from any Firefox context.
// Depending on the context in which the function is being run,
// this could be simplified.
if (typeof window === "undefined") {
//If there is no window defined, get the most recent.
var window=Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow("navigator:browser");
}
if (typeof document === "undefined") {
//If there is no document defined, get it
var document = window.content.document;
}
if (typeof gBrowser === "undefined") {
//If there is no gBrowser defined, get it
var gBrowser = window.gBrowser;
}
//Get the current tab & browser.
let tab = gBrowser.selectedTab;
let browserForTab = gBrowser.getBrowserForTab( tab );
在 Thunderbird 中应该是类似的。
【讨论】: