Fix disabling by removing event listener
This commit is contained in:
parent
412317e06a
commit
0bae437009
1 changed files with 9 additions and 2 deletions
|
@ -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());
|
||||||
|
};
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue