title: Get selected text and selected nodes on a page?
body: <p>When selecting a block of text (possibly spanning across many DOM nodes), is it possible to extract the selected text and nodes using Javascript?</p>
  
  <p>Imagine this HTML code:</p>
  
  <pre><code>&lt;h1&gt;Hello World&lt;/h1&gt;&lt;p&gt;Hi &lt;b&gt;there!&lt;/b&gt;&lt;/p&gt;
  </code></pre>
  
  <p>If the user initiated a mouseDown event starting at "World..." and then a mouseUp even right after "there!", I'm hoping it would return:</p>
  
  <pre><code>Text : { selectedText: "WorldHi there!" },
  Nodes: [ 
    { node: "h1", offset: 6, length: 5 }, 
    { node: "p", offset: 0, length: 16 }, 
    { node: "p &gt; b", offset: 0, length: 6 } 
  ]
  </code></pre>
  
  <p>I've tried putting the HTML into a textarea but that will only get me the selectedText. I haven't tried the <code>&lt;canvas&gt;</code> element but that may be another option.</p>
  
  <p>If not JavaScript, is there a way this is possible using a Firefox extension? </p>