本文介绍了如何编写Thunderbird扩展名(webextension)来修改消息显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Thunderbird编写一个扩展程序,以修改消息显示(例如,插入/替换文本/标记/图像).
不幸的是,缺少文档(由于最近的更改?).

I'd like to write an extension for Thunderbird that modifies the message display (e.g. insert/replace text/markup/image).
Unfortunately, the documentation is lacking (due to recent changes?).

  • https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Thunderbird_extensions
    is outdated

https://developer.thunderbird.net/
还没有有用的例子

https://developer.thunderbird.net/
does not have useful examples (yet)

https://thunderbird-webextensions.readthedocs.io/
也没有示例

https://thunderbird-webextensions.readthedocs.io/
no examples either

可以在

基于> https://github.com/thundernest/sample-extensions/tree/master/messageDisplay

我已经修改了 background.js

browser.messageDisplay.onMessageDisplayed.addListener((tabId, message) => {
  console.log(`Message displayed in tab ${tabId}: ${message.subject}`);
  console.log(message.id);
  browser.messages.getFull(message.id).then((messagepart) => {
      console.log(messagepart);
      body = messagepart['parts'][0]['parts'][0]['body'];
      console.log(body);
      body += "modified!";
      console.log(body);
  });
  browser.windows.getCurrent().then((window)=>{
    console.log(window.type);
  });

  browser.tabs.getCurrent().then((tab)=>{
    console.log("tab",tab);
  });
});

这给了我消息正文(使用魔术索引),但是按预期,该更改不会反映在消息显示中.
返回的窗口类型是normal,而不是messageDisplay.
尽管添加了权限,但tabundefined

which gives me the message body (using magic indexes) but expectedly, the change is not reflected in the message display.
The window type returned is normal, not messageDisplay.
The tab is undefined despite adding permissions

  "permissions": [
    "messagesRead",
    "activeTab",
    "tabs",
    "tabHide"
  ],

但是我认为这是因为脚本以background的身份运行.

but I assume that's because the script is running as background.

因此,我需要在内容上运行脚本/访问选项卡,然后提供一些有关如何修改显示的消息内容的提示(我不想修改消息).

So I'd need a script running on the content / access to the tab and then some hints on how to modify the displayed message content (I do not want to modify the message).

在哪里可以找到与

雷鸟特有的?

在manifest.json中指定content_scripts会导致错误:重新加载插件[email protected]时出错:未定义".

Specifying content_scripts in manifest.json causes "Error: Error reloading addon [email protected]: undefined".

executeScript()似乎也不起作用.

推荐答案

文档 https://thunderbird-webextensions.readthedocs.io/en/68/tabs.html#getcurrent 说:

由于未从选项卡上下文中调用background.js,因此该选项卡未定义.

Since the background.js is not called from a tab context the tab is undefined.

这篇关于如何编写Thunderbird扩展名(webextension)来修改消息显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 21:53