aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-01-25 19:00:36 +0200
committersiikamiika <siikamiika@users.noreply.github.com>2020-02-09 21:51:33 +0200
commit939ad42dacfeff566497f3c2f8e9c64d59b8168d (patch)
tree7adced1abbaacc2ee64fcae92e317ef98ec9a817 /ext/bg/js/backend.js
parentf29abfc5115b06281c18467d7cf7b43bf133da82 (diff)
add global clipboard monitor that spawns popups
TODO: refactor the search page clipboard monitor and popup clipboard monitor to use a common ClipboardMonitor class
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 3cb9ce1d..407dc965 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -34,6 +34,9 @@ class Backend {
this.clipboardPasteTarget = document.querySelector('#clipboard-paste-target');
this.popupWindow = null;
+ this.clipboardPopupTimerId = null;
+ this.clipboardInterval = 250;
+ this.clipboardPreviousText = null;
this.apiForwarder = new BackendApiForwarder();
}
@@ -122,6 +125,20 @@ class Backend {
} else {
this.mecab.stopListener();
}
+
+ window.clearInterval(this.clipboardPopupTimerId);
+ if (options.general.enableClipboardPopups) {
+ this.clipboardPopupTimerId = setInterval(() => {
+ this._onApiClipboardGet()
+ .then((result) => {
+ if (this.clipboardPreviousText === result) {
+ return;
+ }
+ this._onCommandSearch({mode: 'popup', query: result});
+ this.clipboardPreviousText = result;
+ });
+ }, this.clipboardInterval);
+ }
}
async getOptionsSchema() {