aboutsummaryrefslogtreecommitdiff
path: root/src/content/hint.js
blob: 7979cf1c261af24f3b4c74219ed1e6f665b69ad4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import './hint.css';

export default class Hint {
  constructor(target, tag) {
    this.target = target;

    let doc = target.ownerDocument
    let { top, left } = target.getBoundingClientRect();

    this.element = doc.createElement('span');
    this.element.className = 'vimvixen-hint';
    this.element.textContent = tag;
    this.element.style.top = top + 'px';
    this.element.style.left = left + 'px';

    this.show();
    doc.body.append(this.element);
  }

  show() {
    this.element.style.display = 'inline';
  }

  hide() {
    this.element.style.display = 'none';
  }

  remove() {
    this.element.remove();
  }

  activate() {
    if (this.target.tagName.toLowerCase() === 'a') {
      let href = this.target.href;
      window.location.href = href;
    }
  }
}