mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-20 00:48:43 +00:00
22 lines
845 B
TypeScript
22 lines
845 B
TypeScript
|
import { Msg, Page, PluginEvent } from "../../core/types";
|
||
|
import { DocumentEvent } from "../const";
|
||
|
import { Terminal } from "../terminal";
|
||
|
|
||
|
export class InjectEvent {
|
||
|
protected terminal = new Terminal("Inject ");
|
||
|
constructor() {
|
||
|
document.addEventListener(DocumentEvent.Content2Inject, (event: CustomEvent) => {
|
||
|
const pluginEvent: PluginEvent = PluginEvent.create(event.detail);
|
||
|
console.log(...this.terminal.chunkMessage(pluginEvent.toChunk()));
|
||
|
this.onMessage(pluginEvent);
|
||
|
});
|
||
|
}
|
||
|
onMessage(data: PluginEvent) {}
|
||
|
sendMsgToContent(msg: Msg, data: any) {
|
||
|
const detail = new PluginEvent(Page.Inject, Page.Content, msg, data);
|
||
|
console.log(...this.terminal.chunkSend(detail.toChunk()));
|
||
|
const event = new CustomEvent(DocumentEvent.Inject2Content, { detail });
|
||
|
document.dispatchEvent(event);
|
||
|
}
|
||
|
}
|