javascript - 使用 Javascript 获取雷鸟邮件项目正文内容?

标签 javascript thunderbird thunderbird-addon

我正在开发一个雷鸟扩展。我想获取主窗口中的邮件项目内容并撰写邮件窗口。我怎样才能实现这一点?

问候 三州

最佳答案

当您对 Thunderbird 窗口之一中的某些操作感兴趣时,了解它在 XUL DOM 中如何实现的方法是安装 [add-on][2] [DOM Inspector][3 ] 并用它来研究 DOM 的内容是什么样的。您可能还需要 [Element Inspector][4] 附加组件,它是 DOM Inspector 的一个非常有用的补充(按住 Shift 键并右键单击可打开单击元素的 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 中应该类似。

关于javascript - 使用 Javascript 获取雷鸟邮件项目正文内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25909919/

相关文章:

html - 强制 Thunderbird 中的 html 电子邮件在容器中 float 元素

css - 在盒子内实现没有宽度的拆分器

javascript - 获取 Thunderbird 附件的名称

dictionary - 为 Thunderbird 拼写检查添加新语言

javascript - 如何在 JQuery 验证器的 invalidHandler 中显示消息

javascript - 在reactjs中登录主页后数据不刷新

java - 来自外部软件的 Thunderbird 脚本

javascript - Node.js 无法读取未定义的属性 'on'

javascript - 在循环中每收到第 10 个数据包运行函数

email - 在 Thunderbird 扩展中获取邮件发件人