diff options
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/injected.coffee | 20 | ||||
| -rw-r--r-- | content_scripts/link_hints.coffee | 3 | 
2 files changed, 23 insertions, 0 deletions
| diff --git a/content_scripts/injected.coffee b/content_scripts/injected.coffee new file mode 100644 index 00000000..d833d09c --- /dev/null +++ b/content_scripts/injected.coffee @@ -0,0 +1,20 @@ +# The code in `injectedCode()`, below, is injected into the page's own execution context. +# +# This is based on method 2b here: http://stackoverflow.com/a/9517879, and +# @mrmr1993's #1167. + +window.vimiumOnClickAttributeName = "_vimium-has-onclick-listener" + +injectedCode = (vimiumOnClickAttributeName) -> +  # Note the presence of "click" listeners installed with `addEventListener()` (for link hints). +  _addEventListener = Element::addEventListener + +  Element::addEventListener = (type, listener, useCapture) -> +    @setAttribute vimiumOnClickAttributeName, "" if type == "click" +    _addEventListener.apply this, arguments + +script = document.createElement "script" +script.textContent = "(#{injectedCode.toString()})('#{vimiumOnClickAttributeName}')" +(document.head || document.documentElement).appendChild script +script.remove() + diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 0592c96d..e5c6b3ea 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -706,6 +706,9 @@ LocalHints =          isClickable = true          reason = "Open." +    # Detect elements with "click" listeners installed with `addEventListener()`. +    isClickable ||= element.hasAttribute vimiumOnClickAttributeName +      # An element with a class name containing the text "button" might be clickable.  However, real clickables      # are often wrapped in elements with such class names.  So, when we find clickables based only on their      # class name, we mark them as unreliable. | 
