javascriptfirefoxfirefox-addonbrowser-addons

Send selected text to url using context menu as Firefox add-on


I have been doing some hours of research and trial and error on this topic but can't seem to find a decent documentation or suggestions on how to get me started in the right direction.

What I am trying to achieve is create my own Firefox add-on which is supposed to let you select text on any given website, right click and display a context menu option to send the selection to a given website.

Does someone have any experience with any of those issues or is able to come up with something from the top of your head?

Much appreciated.


Solution

  • How do I write a Firefox Addon? gives you some places to get started.

    For what you're doing specifically, you'll want to use an overlay to add an item to the right-click menu, which has id="contentAreaContextMenu". See https://developer.mozilla.org/en/DOM/selection for information on getting the text the user selected (if they didn't select anything then you probably don't need your menu item to show up at all) and then just do something like gBrowser.addTab('myurl.com?q=' + encodeURIComponent(selectedText));