HiraokaHyperTools / sample-extensions

Example extensions for Thunderbird WebExtensions APIs
0 stars 0 forks source link

Modify built in `Write` button (attach drop down) #1

Open kenjiuno opened 4 years ago

kenjiuno commented 4 years ago

Quick research topic of Dropdown support for default menu entry Write,Reply,Forward, etc. | Topicbox

2020-05-08_20h36_53

In TB 68 and prior, this kind of UI mutation has been done by writing add-on with chrome.manifest.

That way is called XUL Overlay (Cross Package Overlays).

However since TB 74 Beta, add-on using XUL Overlay doesn't work any more. Because JavaScript execution context is separated now: Thunderbird privileged context and extension contexts.

TB dev team declares latest TB supports WebExtension (MailExtension) now.

TB still uses XUL. However add-on cannot access XUL directly.

TB dev team allowed us to use WebExtension Experiments in order to access privileged part of Thunderbird including XUL with JavaScript code.

So can we modify builtin Write button by writing WebExtension Experiments?

kenjiuno commented 4 years ago

https://github.com/HiraokaHyperTools/sample-extensions/tree/master/modifyWriteButton sample will replace builtin Write button like following:

replaced-write

At first click [ModifyWriteButton] at top-right, and then click [ReplaceWriteButton] button:

setup

kenjiuno commented 4 years ago

Or you can try replacement of Write button with privileged DevTool:

replace-newmsg-btn

newToolbarButton = MozXULElement.parseXULToFragment(`
  <toolbarbutton id="button-newmsg"
                 type="menu-button"
                 class="toolbarbutton-1"
                 label="Write"
                 tooltiptext="New message">
    <menupopup is="menupopup">
      <menuitem id="button-newmsg-1"
                label="New message alternative 1"/>
      <menuitem id="button-newmsg-2"
                label="New message alternative 2"/>
      <menuitem id="button-newmsg-3"
                label="New message alternative 3"/>
    </menupopup>

  </toolbarbutton>
`)

newToolbarButton.querySelector("#button-newmsg-1").addEventListener("command", () => { alert("1"); event.stopPropagation(); })
newToolbarButton.querySelector("#button-newmsg-2").addEventListener("command", () => { alert("2") })
newToolbarButton.querySelector("#button-newmsg-3").addEventListener("command", () => { alert("3") })

doc = Services.wm.getMostRecentWindow(null).document

newMsg = doc.getElementById("button-newmsg")
newMsg.parentNode.replaceChild(newToolbarButton, newMsg)

newToolbarButton = doc.getElementById("button-newmsg")
newToolbarButton.addEventListener("command", () => alert("0"))
kenjiuno commented 4 years ago

There are still more issues to be solved in this modifyWriteButton extension...

kenjiuno commented 4 years ago

Copied from: https://thunderbird.topicbox.com/groups/addons/Ta0d377f7f4d64034-M1af07002daa494534724b7b1/dropdown-support-for-default-menu-entry-write-reply-forward-etc

browser_action

message_display_action

compose_action

kenjiuno commented 4 years ago

I have tested the script https://github.com/HiraokaHyperTools/sample-extensions/issues/1#issuecomment-625801050 on TB 68.8.0:

tb68-8-write-replacing