blob: d833d09c208cb7a0e34ee74da92b725a40156a41 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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()
 |