add support for looking up definitions for textareas and textboxes
This commit is contained in:
parent
4e3792aba3
commit
e73d2d96c9
@ -182,6 +182,7 @@ class Driver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
searchClear() {
|
searchClear() {
|
||||||
|
destroyImposters();
|
||||||
this.popup.hide();
|
this.popup.hide();
|
||||||
|
|
||||||
if (this.options.scanning.selectText && this.lastTextSource !== null) {
|
if (this.options.scanning.selectText && this.lastTextSource !== null) {
|
||||||
|
@ -70,12 +70,36 @@ function addDefinition(definition, mode) {
|
|||||||
return invokeBgApi('addDefinition', {definition, mode});
|
return invokeBgApi('addDefinition', {definition, mode});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createImposter(element) {
|
||||||
|
const imposter = document.createElement('div');
|
||||||
|
const elementRect = element.getBoundingClientRect();
|
||||||
|
|
||||||
|
imposter.className = 'yomichan-imposter';
|
||||||
|
imposter.innerText = element.value;
|
||||||
|
imposter.style.cssText = window.getComputedStyle(element).cssText;
|
||||||
|
imposter.style.position = 'absolute';
|
||||||
|
imposter.style.top = elementRect.top + 'px';
|
||||||
|
imposter.style.left = elementRect.left + 'px';
|
||||||
|
imposter.style.zIndex = 2147483646;
|
||||||
|
document.body.appendChild(imposter);
|
||||||
|
|
||||||
|
imposter.scrollTop = element.scrollTop;
|
||||||
|
imposter.scrollLeft = element.scrollLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
function destroyImposters() {
|
||||||
|
for (const element of document.getElementsByClassName('yomichan-imposter')) {
|
||||||
|
element.parentNode.removeChild(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function textSourceFromPoint(point) {
|
function textSourceFromPoint(point) {
|
||||||
const element = document.elementFromPoint(point.x, point.y);
|
const element = document.elementFromPoint(point.x, point.y);
|
||||||
if (element !== null) {
|
if (element !== null) {
|
||||||
const names = ['IMG', 'INPUT', 'BUTTON', 'TEXTAREA'];
|
if (element.nodeName === 'IMG' || element.nodeName === 'BUTTON') {
|
||||||
if (names.includes(element.nodeName)) {
|
|
||||||
return new TextSourceElement(element);
|
return new TextSourceElement(element);
|
||||||
|
} else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
|
||||||
|
createImposter(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Yomichan",
|
"name": "Yomichan",
|
||||||
"version": "1.0.9",
|
"version": "1.0.10",
|
||||||
|
|
||||||
"description": "Japanese dictionary with Anki integration",
|
"description": "Japanese dictionary with Anki integration",
|
||||||
"icons": {"16": "img/icon16.png", "48": "img/icon48.png", "128": "img/icon128.png"},
|
"icons": {"16": "img/icon16.png", "48": "img/icon48.png", "128": "img/icon128.png"},
|
||||||
|
Loading…
Reference in New Issue
Block a user