diff options
Diffstat (limited to 'src/content/components/hint.js')
-rw-r--r-- | src/content/components/hint.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/content/components/hint.js b/src/content/components/hint.js new file mode 100644 index 0000000..cc46fd6 --- /dev/null +++ b/src/content/components/hint.js @@ -0,0 +1,36 @@ +import './hint.css'; + +export default class Hint { + constructor(target, tag) { + if (!(document.body instanceof HTMLElement)) { + throw new TypeError('target is not an HTMLElement'); + } + + this.target = target; + + let doc = target.ownerDocument; + let { top, left } = target.getBoundingClientRect(); + let { scrollX, scrollY } = window; + + this.element = doc.createElement('span'); + this.element.className = 'vimvixen-hint'; + this.element.textContent = tag; + this.element.style.left = left + scrollX + 'px'; + this.element.style.top = top + scrollY + 'px'; + + this.show(); + doc.body.append(this.element); + } + + show() { + this.element.style.display = 'inline'; + } + + hide() { + this.element.style.display = 'none'; + } + + remove() { + this.element.remove(); + } +} |