
module.exports = function (root, cb) {
  root.addEventListener('click', (ev) => {
    if (ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey || ev.defaultPrevented) {
      return true
    }

    let anchor = null
    for (let n = ev.target; n.parentNode; n = n.parentNode) {
      if (n.nodeName === 'A') {
        anchor = n
        break
      }
    }
    if (!anchor) return true

    let href = anchor.getAttribute('href')

    try {
      href = decodeURIComponent(href)
    } catch (e) {
      // Safely ignore error because href isn't URI-encoded.
    }

    if (href) {
      let isUrl
      let url

      try {
        url = new URL(href)
        isUrl = true
      } catch (e) {
        isUrl = false
      }

      if (isUrl && (url.host || url.protocol === 'magnet:')) {
        cb(href, true)
      } else if (href !== '#') {
        cb(href, false, anchor.anchor)
      }
    }

    ev.preventDefault()
    ev.stopPropagation()
  })
}

@@ -425,16 +425,50 @@
 href')%0A%0A
+    if (href.startsWith('#')) %7B%0A  
     try 
@@ -465,24 +465,26 @@
       try %7B%0A
+  
       href =
@@ -509,24 +509,26 @@
 t(href)%0A    
+  
 %7D catch (e) 
@@ -525,24 +525,26 @@
 catch (e) %7B%0A
+  
       // Saf
@@ -592,16 +592,24 @@
 ncoded.%0A
+      %7D%0A
     %7D%0A%0A 

Fix URI decode error breaking messages