SerFer
SerFer

Reputation: 21

Access the clicked item in Thunderbird Add-on

The purpose of my add-on is to export a single email or an entire folder for later analysis. At the moment I have created a field within the menu for the single item, but I don't understand how to access the item I right-clicked on. Can someone explain to me how to access the item, be it the individual email or the box?

/*
Called when the item has been created, or when creation failed due to an error.
We'll just log success/failure here.
*/
function onCreated() {
  if (browser.runtime.lastError) {
    console.log(`Error: ${browser.runtime.lastError}`);
  } else {
    console.log("Item created successfully");
  }
}

/*
Create all the context menu items.
*/
browser.menus.create({
  id: "log-selection",
  title: browser.i18n.getMessage("menuItemSelectionLogger"),
  contexts: ["selection"]
}, onCreated);

browser.menus.create({
  id: "analyse",
  type: "radio",
  title: browser.i18n.getMessage("menuItemAnalyse"),
  contexts: ["all"],
  checked: true,
  icons: {
    "16": "icons/paint-green-16.png",
    "32": "icons/paint-green-32.png"
  }
}, onCreated);

browser.menus.create({
  id: "export",
  type: "radio",
  title: browser.i18n.getMessage("menuItemExport"),
  contexts: ["all"],
  checked: true,
  icons: {
    "16": "icons/paint-green-16.png",
    "32": "icons/paint-green-32.png"
  }
}, onCreated);


/*
The click event listener, where we perform the appropriate action given the
ID of the menu item that was clicked.
*/
browser.menus.onClicked.addListener((info, tab) => {
  switch (info.menuItemId) {
    case "log-selection":
      console.log(info.selectionText);
      break;
    case "analyse":
      break;

    case "export":
      break;
  }
});

Upvotes: 2

Views: 110

Answers (0)

Related Questions