From 0bae437009a64b522c43b671ce210f11cce67bff Mon Sep 17 00:00:00 2001 From: a Date: Thu, 23 Jul 2020 20:18:56 +0200 Subject: [PATCH] Fix disabling by removing event listener --- src/content_script.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/content_script.ts b/src/content_script.ts index 6da726f..76e31dc 100644 --- a/src/content_script.ts +++ b/src/content_script.ts @@ -3,6 +3,7 @@ import { browser } from "webextension-polyfill-ts"; interface WindowHack { [index: string]: any; } + (() => { //Make sure our script only runs once let name = browser.runtime.getManifest().name; @@ -11,11 +12,17 @@ interface WindowHack { } (window as WindowHack)[name] = true; - let ON = false; browser.runtime.onMessage.addListener((c: command) => { switch (c.command) { case commands.toggle: - ON = c.value; + document.removeEventListener("selectionchange", onSelectionChange); + if (c.value) { + document.addEventListener("selectionchange", onSelectionChange); + } } }); + + const onSelectionChange = () => { + console.log(document.getSelection().toString()); + }; })();