/**
 * Goes up in the tree from a given node and
 * returns the first node being a link.
 *
 * This is a recursive function to make sure to handle the
 * `href` attribute of the real link.
 *
 *
 * Example: <a href="#"><em>Child node without `href`</em></a>
 * In this case, the `em` node doesn't have a `href` attribute
 * so it needs to fall back to `a`.
 *
 * @param {object} node The node to get the link from
 * @returns {object} the first node having a `href` property
 */
const getLink = node => {
  if (!node) {
    return undefined
  }

  return node.href ? node : getLink(node.parentNode)
}

/**
 * Handles the click event.
 *
 * Fired if the node is clicked pressing the correct key combinaison
 * and is a link.
 * See https://github.com/francoischalifour/incognito-link#usage
 *
 * @param {object} e The event
 */
const onClick = e => {
  if (!e.shiftKey && !e.altKey) {
    return
  }

  const link = getLink(e.target)

  if (!link) {
    return
  }

  e.preventDefault()

  // Send the action to event listeners in `background.js`
  chrome.runtime.sendMessage({
    action: 'CREATE_INCOGNITO_WINDOW',
    url: link.href
  })
}

document.addEventListener('DOMContentLoaded', () => {
  document.body.addEventListener('click', onClick)
})

@@ -19,37 +19,42 @@
 the 
-tree from a given node
+nodelist until it finds a link
  and
-%0A *
  ret
@@ -62,35 +62,10 @@
 rns 
+i
 t
-he first node being a link
 .%0A *
@@ -165,19 +165,16 @@
 ink.%0A *%0A
- *%0A
  * Examp
@@ -176,16 +176,19 @@
 Example:
+%0A *
  %3Ca href
@@ -197,46 +197,45 @@
 #%22%3E%3C
-em%3EChild node without %60href%60%3C/em
+code%3EHTMLAnchorElement%3C/code
 %3E%3C/a%3E%0A
+ *%0A
  * I
@@ -252,18 +252,20 @@
 e, the %60
+cod
 e
-m
 %60 node d
@@ -448,16 +448,37 @@
 property
+, %60undefined%60 if none
 %0A */%0Acon
@@ -608,31 +608,66 @@
 %0A * 
-Handles the click event
+Dispatches the action to event listeners in the background
 .%0A *
@@ -1021,67 +1021,8 @@
 ()%0A%0A
-  // Send the action to event listeners in %60background.js%60%0A
   ch
@@ -1114,16 +1114,115 @@
   %7D)%0A%7D%0A%0A
+/*%0A * Binds the listener on the document object to intercept any links%0A * added in the future.%0A */%0A
 document

Improve docs