summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-02-07 21:46:37 -0800
committerAlex Yatskov <alex@foosoft.net>2017-02-07 21:46:37 -0800
commite73d2d96c9cadce1364ae48a0dc68e24f2019c72 (patch)
treef1984328b561f7fc9a960b45e8b29a57b9835083
parent4e3792aba319b52f957c70347e859f677972e4e2 (diff)
add support for looking up definitions for textareas and textboxes1.0.10
-rw-r--r--ext/fg/js/driver.js1
-rw-r--r--ext/fg/js/util.js28
-rw-r--r--ext/manifest.json2
3 files changed, 28 insertions, 3 deletions
diff --git a/ext/fg/js/driver.js b/ext/fg/js/driver.js
index 8904c12c..97f29f89 100644
--- a/ext/fg/js/driver.js
+++ b/ext/fg/js/driver.js
@@ -182,6 +182,7 @@ class Driver {
}
searchClear() {
+ destroyImposters();
this.popup.hide();
if (this.options.scanning.selectText && this.lastTextSource !== null) {
diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js
index ba872467..a7533846 100644
--- a/ext/fg/js/util.js
+++ b/ext/fg/js/util.js
@@ -70,12 +70,36 @@ function 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) {
const element = document.elementFromPoint(point.x, point.y);
if (element !== null) {
- const names = ['IMG', 'INPUT', 'BUTTON', 'TEXTAREA'];
- if (names.includes(element.nodeName)) {
+ if (element.nodeName === 'IMG' || element.nodeName === 'BUTTON') {
return new TextSourceElement(element);
+ } else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
+ createImposter(element);
}
}
diff --git a/ext/manifest.json b/ext/manifest.json
index e296ec06..ba7e36e6 100644
--- a/ext/manifest.json
+++ b/ext/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Yomichan",
- "version": "1.0.9",
+ "version": "1.0.10",
"description": "Japanese dictionary with Anki integration",
"icons": {"16": "img/icon16.png", "48": "img/icon48.png", "128": "img/icon128.png"},