Add commands
This commit is contained in:
parent
e300cb2e74
commit
412317e06a
3 changed files with 22 additions and 4 deletions
|
@ -10,5 +10,12 @@ interface WindowHack {
|
|||
return;
|
||||
}
|
||||
(window as WindowHack)[name] = true;
|
||||
console.log("loaded content_script");
|
||||
|
||||
let ON = false;
|
||||
browser.runtime.onMessage.addListener((c: command) => {
|
||||
switch (c.command) {
|
||||
case commands.toggle:
|
||||
ON = c.value;
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -21,8 +21,11 @@ customElements.define("extension-toggle", ExtensionToggle, {
|
|||
});
|
||||
|
||||
const toggle = document.querySelector("button[is=extension-toggle]");
|
||||
toggle.addEventListener("extensionToggled", (e: CustomEvent) =>
|
||||
console.log(`aaa: ${e.detail}`)
|
||||
);
|
||||
toggle.addEventListener("extensionToggled", async (e: CustomEvent) => {
|
||||
let tab = await browser.tabs.query({ active: true, currentWindow: true });
|
||||
let com = { command: commands.toggle, value: e.detail };
|
||||
browser.tabs.sendMessage(tab[0].id, com);
|
||||
});
|
||||
|
||||
//Runs in the current tab
|
||||
browser.tabs.executeScript({ file: "/content_script.bundle.js" });
|
||||
|
|
8
src/types.d.ts
vendored
Normal file
8
src/types.d.ts
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
declare const enum commands {
|
||||
toggle = 0,
|
||||
}
|
||||
interface ToggleCommand {
|
||||
command: commands.toggle;
|
||||
value: boolean;
|
||||
}
|
||||
type command = ToggleCommand;
|
Loading…
Reference in a new issue