问题
I am a beginner in thunderbird addons so I really appreciate if you can help me. I am trying to find a way in my background javascript to check whenever a user has opened the window for create a new message, reply a message and forward a message. I want to put a default text in the message window before the user is gonna send it. I know thunderbird 78+ should only uses web extension APIs and i found this Compose API but how to use it in my background script.
https://thunderbird-webextensions.readthedocs.io/en/78/compose.html
回答1:
It looks like setComposeDetails() is what you want.
setComposeDetails(tabId, details)
Updates the compose window. Specify only fields that you want to change. Currently only the to/cc/bcc/replyTo/followupTo/newsgroups fields and the subject are implemented.
tabId
(integer)details
(ComposeDetails)
I have note tried it, but I suppose that either details.body
or details.plainTextBody
from the ComposeDetails object can be used to pass the default text you want to use. So I would try something like this in the background script:
let details = {
body: "This is my default text",
};
browser.messages.setComposeDetails(tabId, details);
You might have to combine it with a call to messages.getComposeDetails()
if empty fields in details
reset the values in the composer window (I don't know).
If you want to call this when the user opens a new compose window, I would look at the window.onCreated
event. If you want to do it right before the message is sent instead, you should look at the compose.onBeforeSend
event. All of them are described in the API documentation.
来源:https://stackoverflow.com/questions/64798401/thunderbird78-how-to-check-for-message-create-reply-and-forward