Skip to content

Commit 8275852

Browse files
committed
fix: addressed comments
1 parent 1757b8e commit 8275852

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ export const TAXY_ELEMENT_SELECTOR = "data-taxy-node-id";
22
export const VISIBLE_TEXT_ATTRIBUTE_NAME = "data-web-wand-visible-text";
33
export const ARIA_LABEL_ATTRIBUTE_NAME = "data-web-wand-aria-label";
44
export const WEB_WAND_LABEL_ATTRIBUTE_NAME = "data-web-wand-label";
5+
export const SetAPIKey = "SetAPIKey";
6+
export const SetTask = "SetTask";
7+
export const RunTask = "RunTask";
58

69
// read from env
710
export const debugMode = import.meta.env.VITE_DEBUG_MODE === "true";

src/pages/content/injected.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
// The content script runs inside each page this extension is enabled on
22

3+
import { RunTask, SetAPIKey, SetTask } from "@root/src/constants";
34
import { initializeRPC } from "./domOperations";
45

56
initializeRPC();
67

7-
document.addEventListener("SetAPIKey", function (event) {
8-
const customEvent = event as CustomEvent;
9-
chrome.runtime.sendMessage({
10-
type: "API_KEY",
11-
value: customEvent.detail.value,
12-
});
8+
document.addEventListener(SetAPIKey, function (event) {
9+
if (isCustomEvent(event)) {
10+
const customEvent = event as CustomEvent;
11+
chrome.runtime.sendMessage({
12+
type: "API_KEY",
13+
value: customEvent.detail.value,
14+
});
15+
}
1316
});
1417

15-
document.addEventListener("SetTask", function (event) {
16-
const customEvent = event as CustomEvent;
17-
chrome.runtime.sendMessage({
18-
type: "SET_TASK",
19-
value: customEvent.detail.value,
20-
});
18+
document.addEventListener(SetTask, function (event) {
19+
if (isCustomEvent(event)) {
20+
const customEvent = event as CustomEvent;
21+
chrome.runtime.sendMessage({
22+
type: "SET_TASK",
23+
value: customEvent.detail.value,
24+
});
25+
}
2126
});
2227

23-
document.addEventListener("RunTask", function () {
28+
document.addEventListener(RunTask, function () {
2429
chrome.runtime.sendMessage({ type: "RUN_TASK" });
2530
});
2631

@@ -46,7 +51,18 @@ chrome.runtime.onMessage.addListener(function (message) {
4651
}
4752
});
4853

49-
function dispatchCustomEvent(eventType: string, detail) {
54+
type CustomEventDetail = {
55+
type: string;
56+
status: string;
57+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
58+
data: any;
59+
};
60+
61+
function dispatchCustomEvent(eventType: string, detail: CustomEventDetail) {
5062
const event = new CustomEvent(eventType, { detail });
5163
document.dispatchEvent(event);
5264
}
65+
66+
function isCustomEvent(event: Event): event is CustomEvent {
67+
return "detail" in event;
68+
}

0 commit comments

Comments
 (0)