Fix disabling by removing event listener

This commit is contained in:
a 2020-07-23 20:18:56 +02:00
parent 412317e06a
commit 0bae437009

View file

@ -3,6 +3,7 @@ import { browser } from "webextension-polyfill-ts";
interface WindowHack { interface WindowHack {
[index: string]: any; [index: string]: any;
} }
(() => { (() => {
//Make sure our script only runs once //Make sure our script only runs once
let name = <string>browser.runtime.getManifest().name; let name = <string>browser.runtime.getManifest().name;
@ -11,11 +12,17 @@ interface WindowHack {
} }
(window as WindowHack)[name] = true; (window as WindowHack)[name] = true;
let ON = false;
browser.runtime.onMessage.addListener((c: command) => { browser.runtime.onMessage.addListener((c: command) => {
switch (c.command) { switch (c.command) {
case commands.toggle: case commands.toggle:
ON = c.value; document.removeEventListener("selectionchange", onSelectionChange);
if (c.value) {
document.addEventListener("selectionchange", onSelectionChange);
}
} }
}); });
const onSelectionChange = () => {
console.log(document.getSelection().toString());
};
})(); })();