From 6eca605912314e8cbdefabc69f78804f655d2c29 Mon Sep 17 00:00:00 2001 From: Kaanium Date: Sat, 8 Jul 2023 19:38:36 +0300 Subject: [PATCH 1/2] Fix search pages clipboard monitor --- .eslintrc.json | 1 + ext/js/comm/clipboard-monitor.js | 38 +++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index b5328f41bb..780706bf2f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -386,6 +386,7 @@ "serializeError": "readonly", "deserializeError": "readonly", "isObject": "readonly", + "document": "readonly", "stringReverse": "readonly", "promiseTimeout": "readonly", "escapeRegExp": "readonly", diff --git a/ext/js/comm/clipboard-monitor.js b/ext/js/comm/clipboard-monitor.js index fbf56432a2..26ad713b1f 100644 --- a/ext/js/comm/clipboard-monitor.js +++ b/ext/js/comm/clipboard-monitor.js @@ -16,6 +16,7 @@ * along with this program. If not, see . */ + class ClipboardMonitor extends EventDispatcher { constructor({japaneseUtil, clipboardReader}) { super(); @@ -30,6 +31,23 @@ class ClipboardMonitor extends EventDispatcher { start() { this.stop(); + // Continuously selecting and focusing on an element makes the search + // Function is unusable manually this code disables the function + // If the mouse is over the content + const content = document.querySelector('.content-body-inner'); + + let isMouseAbove = false; + + content.addEventListener('mouseover', handleMouseover); + content.addEventListener('mouseleave', handleMouseleave); + + function handleMouseover() { + isMouseAbove = true; + } + + function handleMouseleave() { + isMouseAbove = false; + } // The token below is used as a unique identifier to ensure that a new clipboard monitor // hasn't been started during the await call. The check below the await call // will exit early if the reference has changed. @@ -40,7 +58,9 @@ class ClipboardMonitor extends EventDispatcher { let text = null; try { - text = await this._clipboardReader.getText(false); + if (isMouseAbove) { text = this._previousText; } else { + text = this.paste(); + } } catch (e) { // NOP } @@ -66,6 +86,22 @@ class ClipboardMonitor extends EventDispatcher { intervalCallback(); } + paste() { + const previouslyFocusedElement = document.activeElement; + const ta = document.createElement('textarea'); + ta.style.cssText = + 'opacity:0; position:fixed; width:1px; height:1px; top:0; left:0;'; + document.body.appendChild(ta); + + ta.focus(); + ta.select(); + document.execCommand('paste'); + const a = ta.value; + ta.remove(); + previouslyFocusedElement.focus(); + + return a; + } stop() { this._timerToken = null; this._previousText = null; From 9dd0bf059edfc0ac1b516f2742bdc99ecc37ab7d Mon Sep 17 00:00:00 2001 From: Kaanium Date: Sun, 9 Jul 2023 09:36:26 +0300 Subject: [PATCH 2/2] Enable background clipboard text monitoring setting crashes the extension I commented it out. - A future fix could be running an iframe element constantly in the background if mv3 doesn't include a better way do implement this --- ext/settings.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/settings.html b/ext/settings.html index 62e06e983f..ab3d7bd43e 100644 --- a/ext/settings.html +++ b/ext/settings.html @@ -1927,7 +1927,7 @@

Yomitan Settings

-
+