MozillaZine

Custom button to get the URL of a message: WebExtension?

User Help for Mozilla Thunderbird
user2018
 
Posts: 14
Joined: September 23rd, 2018, 11:07 am

Post Posted January 7th, 2020, 5:11 am

Until the latest versions of Thunderbird, I was successfully executing the following JavaScript function by attaching it to a custom button, following the procedure described in https://developer.mozilla.org/en-US/doc ... bar_button to associate a JavaScript script to a button:

var hdr = gFolderDisplay.selectedMessage;
var uriStr = hdr.folder.getUriForMsg(hdr);
alert(uriStr);

The problem is that the extension created is said not to be compatible with Thunderbird 68.

As far as I understand, the only possible solution is to transform this into a WebExtension (https://developer.thunderbird.net/add-o ... -extension), but if I do this I cannot find what I need in the WebExtension API (e.g., gFolderDisplay does not exist).

I can execute the JavaScript code shown above without problems in Thunderbird 68 by using Tools -> Developer Tools -> Scratchpad. However, I need to associate the code to some button, as otherwise typing or pasting the JavaScript code each time is really inconvenient (even though it works). As commented above, my previous solution (based on Custom_toolbar_button) seems not to work anymore due to some incompatibility with the latest Thunderbird versions, and with WebExtension I cannot execute the same code and I could not find any equivalent.

Any idea that can help with this is very welcome.

morat
 
Posts: 3676
Joined: February 3rd, 2009, 6:29 pm

Post Posted January 7th, 2020, 8:51 am

I would create a Thunderbird 68 compatible WebExtension using a manifest.json file with the legacy property that creates a toolbar button using an overlay.

e.g.

ThunderKdB search
http://github.com/cleidigh/ThunderKdB/search?q=customizeToolbar+path:/xall/x68+filename:chrome.manifest

Folder Filters Button
http://github.com/cleidigh/ThunderKdB/tree/1058170da77281ff47dd022902fa084e8a824fe8/xall/x68/5731-folder-filters-button/src
http://addons.thunderbird.net/thunderbird/addon/5731

There is a simple way to test an unpacked extension.

* open the extensions folder

e.g. C:\ThunderbirdPortable\Data\profile\extensions

* create a text file and put the path to the extension inside

e.g. C:\Tweaks

note: last character cannot be a newline or space

* save the file with the id of the extension as its name

e.g. tweaks@example.com

note: do not use .txt extension

* restart the application

About Thunderbird
http://developer.thunderbird.net/

Thunderbird WebExtensions APIs
http://thunderbird-webextensions.readthedocs.io/
http://thunderbird-webextensions.readthedocs.io/en/68/legacy.html

user2018
 
Posts: 14
Joined: September 23rd, 2018, 11:07 am

Post Posted January 12th, 2020, 12:50 pm

Thank you very much for this interesting idea and the links.

I'm a bit confused about how to proceed (I have not programmed any addon, just some custom buttons). With the legacy property do you mean putting this in the manifest.json file?:

"legacy": {
"type": "xul",
...

And then I need an overlay.js file?

I tried to look at the examples, but I am still quite unsure about how I can reuse the previous custom button toolbars code (following the example at https://developer.mozilla.org/en-US/doc ... bar_button). Does re-using it require a lot of effort? As this approach would use a legacy property, could it be easily broken in an upcoming Thunderbird release?

Thank you for any idea.

morat
 
Posts: 3676
Joined: February 3rd, 2009, 6:29 pm

Post Posted January 12th, 2020, 6:15 pm

I sent a link to an example extension in a private message. It shows the selected message url in a dialog.

The following snippet in the manifest.json file...

Code: Select all
"legacy": true,

is the same as...

Code: Select all
"legacy": {
  "type" : "xul"
},

since xul is the default. (see the legacy docs for more info)

Support for legacy addons to be dropped
http://forums.mozillazine.org/viewtopic.php?f=28&t=3057657

vasmancs
 
Posts: 1
Joined: January 14th, 2020, 7:59 pm

Post Posted January 14th, 2020, 8:01 pm

Could you please share the manifest.json if you have managed to convert it?

morat
 
Posts: 3676
Joined: February 3rd, 2009, 6:29 pm

Post Posted January 15th, 2020, 8:01 am

@vasmancs

Examples of manifest.json file with legacy property
http://github.com/cleidigh/ThunderKdB/s ... ifest.json

Return to Thunderbird Support


Who is online

Users browsing this forum: No registered users and 6 guests