title: Reverse engineering a Firefox extension
body: <p>I'm a young developer and am just trying my hand at JavaScript for the first time this week after coming from a background in Java. I found a nice add-on for Firefox that allows users to copy links from selected text. Its relatively small but I'd like to try configure it so it runs from a button rather than a (rightclick/select event)</p>
  
  <p>DISCLAIMER: The extension in question is open source and licensed under GNU General Public License, version 2.0</p>
  
  <p>I'm not reverse engineering anyone's hard work, I'm just trying to figure out what makes add-ons tick and how to apply its workings to something that's not an add-on.</p>
  
  <p>The source is available here:
  <a href="https://addons.mozilla.org/en-US/firefox/files/browse/77730/" rel="nofollow">https://addons.mozilla.org/en-US/firefox/files/browse/77730/</a> (it's quite small, just one jar so don't be afraid to read)</p>
  
  <p>Back to the point: it's a neat little add-on that allows users to select multiple links in a  web page and copy/paste the links selected by right clicking the text and selecting copy selected links. </p>
  
  <p>So the 2 parts of my question: </p>
  
  <ol>
  <li><p>How do I run this type of add-on from a button instead of a right click? (I'm assuming it has something to do with the EOL function)</p></li>
  <li><p>Is there anything I need to be aware of when converting add-ons other than cross browser compatibility? Should I be contacting the author for help or would that offend?</p></li>
  </ol>
  
  <p>Any and all help appreciated!</p>
  
  <p>*
  *</p>
  
  <p>I'm pretty sure I'm passing 'true' to welcome for no reason.
  Also pretty sure turning this into an internal type script
  My small attempt at taking the source and making something out of it:</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;input type="button" id="grablinkstest" value="CopyLinks" onclick="welcome(true);"/&gt;
  </code></pre>
  
  <p>JAVASCRIPT:</p>
  
  <pre><code>function welcome() {
      alert("welcome command works");
      var focusedWindow = document.commandDispatcher.focusedWindow;
      var focusedDoc = document.commandDispatcher.focusedWindow.document;
      var argc = gCopyLinks.GetLinks.arguments.length;
      var argv = gCopyLinks.GetLinks.arguments;
      var reMask;
  
      var selLinks = [];
      for( i = 0; i &lt; focusedDoc.links.length; i++) {
          if((!bSelected || focusedWindow.getSelection().containsNode(focusedDoc.links[i], true)) &amp;&amp; (argc &lt;= 1 || focusedDoc.links[i].href.match(reMask))) {
              selLinks[j] = focusedDoc.links[i].href;
              j++;
          }
      }
  
  }
  </code></pre>