This repository has been archived on 2020-04-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Vim-Vixen/src/content/hint.js
2017-08-22 21:55:16 +09:00

43 lines
941 B
JavaScript

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 = window.scrollX;
let scrollY = window.scrollY;
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();
}
activate() {
if (this.target.tagName.toLowerCase() === 'a') {
this.target.click();
}
}
}