scordi-extension 1.14.3 → 1.14.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +605 -587
- package/package.json +13 -4
- package/dist/.vite/manifest.json +0 -67
- package/dist/assets/DataExtractBlock-B7AuVonx.js +0 -6
- package/dist/assets/index-B9PKMhAi.js +0 -6
- package/dist/assets/index-CMlx_xZE.css +0 -1
- package/dist/assets/index-CZjAbH8z.js +0 -1
- package/dist/assets/index-DkFIvNAm.css +0 -1
- package/dist/assets/index-r5QRyJ4m.js +0 -1
- package/dist/assets/index.html-BIbPySIb.js +0 -74
- package/dist/assets/index.html-cr-_Qdxq.js +0 -49
- package/dist/assets/index.ts-BqxJYCmp.js +0 -160
- package/dist/assets/internal-messages-Drf0Gb9U.js +0 -1
- package/dist/assets/loading-page-1924caaa.js +0 -51
- package/dist/assets/main.tsx-BEyI95mZ.js +0 -2
- package/dist/assets/main.tsx-BKzdlur-.js +0 -2
- package/dist/assets/main.tsx-loader-BYP9L25W.js +0 -13
- package/dist/assets/main.tsx-loader-FYb0LhDu.js +0 -13
- package/dist/assets/schemas-C8r0jYHO.js +0 -21
- package/dist/logo.png +0 -0
- package/dist/manifest.json +0 -55
- package/dist/public/logo.png +0 -0
- package/dist/service-worker-loader.js +0 -3
- package/dist/src/blocks/AiParseDataBlock.ts.js +0 -101
- package/dist/src/blocks/ClearValueFormBlock.ts.js +0 -55
- package/dist/src/blocks/DataExtractBlock.ts.js +0 -28
- package/dist/src/blocks/ElementExistsBlock.ts.js +0 -26
- package/dist/src/blocks/EventClickBlock.ts.js +0 -143
- package/dist/src/blocks/FetchApiBlock.ts.js +0 -50
- package/dist/src/blocks/GetAttributeValueBlock.ts.js +0 -33
- package/dist/src/blocks/GetElementDataBlock.ts.js +0 -114
- package/dist/src/blocks/GetTextBlock.ts.js +0 -152
- package/dist/src/blocks/GetValueFormBlock.ts.js +0 -52
- package/dist/src/blocks/KeypressBlock.ts.js +0 -89
- package/dist/src/blocks/SaveAssetsBlock.ts.js +0 -35
- package/dist/src/blocks/ScrollBlock.ts.js +0 -111
- package/dist/src/blocks/SetValueFormBlock.ts.js +0 -56
- package/dist/src/blocks/WaitBlock.ts.js +0 -24
- package/dist/src/blocks/index.ts.js +0 -163
- package/dist/src/blocks/types.ts.js +0 -11
- package/dist/src/content/elements/finders/CssSelector.ts.js +0 -51
- package/dist/src/content/elements/finders/ElementSelector.ts.js +0 -20
- package/dist/src/content/elements/finders/IframeSelector.ts.js +0 -32
- package/dist/src/content/elements/finders/ShadowDOMSelector.ts.js +0 -38
- package/dist/src/content/elements/finders/XPathFinder.ts.js +0 -32
- package/dist/src/content/elements/index.ts.js +0 -26
- package/dist/src/content/elements/utils/CSSSelectorGenerator.ts.js +0 -72
- package/dist/src/content/elements/utils/XPathGenerator.ts.js +0 -62
- package/dist/src/content/handler/ExternalMessageHandler.ts.js +0 -78
- package/dist/src/content/handler/InternalMessageHandler.ts.js +0 -18
- package/dist/src/content/kernel/MessageKernel.ts.js +0 -83
- package/dist/src/content/main.tsx-loader.js +0 -22
- package/dist/src/content/main.tsx.js +0 -13
- package/dist/src/content/utils/index.ts.js +0 -1
- package/dist/src/content/utils/synchronizedLock.ts.js +0 -35
- package/dist/src/popup/index.html +0 -12
- package/dist/src/types/internal-messages.ts.js +0 -15
- package/dist/vendor/.vite-deps-chunk-PR4QN5HX.js__v--57e88532.js +0 -42
- package/dist/vendor/.vite-deps-chunk-PR4QN5HX.js__v--ba9031c0.js +0 -42
- package/dist/vendor/.vite-deps-chunk-VBBIEGWT.js__v--57e88532.js +0 -4156
- package/dist/vendor/.vite-deps-jsonata.js__v--5da6ca24.js +0 -5761
- package/dist/vendor/.vite-deps-jsonata.js__v--ba9031c0.js +0 -5761
- package/dist/vendor/.vite-deps-zod.js__v--13965f26.js +0 -219
- package/dist/vendor/.vite-deps-zod.js__v--ba9031c0.js +0 -12651
- package/dist/vendor/crx-client-port.js +0 -66
- package/dist/vendor/crx-client-preamble.js +0 -4
- package/dist/vendor/react-refresh.js +0 -670
- package/dist/vendor/vite-client.js +0 -1098
- package/dist/vendor/vite-dist-client-env.mjs.js +0 -19
- package/dist/vendor/webcomponents-custom-elements.js +0 -47
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import z from "/vendor/.vite-deps-zod.js__v--13965f26.js";
|
|
2
|
-
import { BaseBlockSchema } from "/src/blocks/types.ts.js";
|
|
3
|
-
import { findElement } from "/src/content/elements/index.ts.js";
|
|
4
|
-
export const EventClickBlockSchema = BaseBlockSchema.extend({
|
|
5
|
-
name: z.literal("event-click"),
|
|
6
|
-
textFilter: z.object({
|
|
7
|
-
text: z.union([z.string(), z.array(z.string())]),
|
|
8
|
-
mode: z.enum(["exact", "contains", "startsWith", "endsWith", "regex"])
|
|
9
|
-
}).optional()
|
|
10
|
-
});
|
|
11
|
-
export function validateEventClickBlock(data) {
|
|
12
|
-
return EventClickBlockSchema.parse(data);
|
|
13
|
-
}
|
|
14
|
-
export async function handlerEventClick(data) {
|
|
15
|
-
try {
|
|
16
|
-
const { selector = "", findBy = "cssSelector", option, textFilter } = data;
|
|
17
|
-
if (!selector) {
|
|
18
|
-
throw new Error("Selector is required for event-click block");
|
|
19
|
-
}
|
|
20
|
-
const elements = await findElement({ selector, findBy, option });
|
|
21
|
-
if (!elements) {
|
|
22
|
-
throw new Error("Element not found for clicking");
|
|
23
|
-
}
|
|
24
|
-
let targetElement;
|
|
25
|
-
if (Array.isArray(elements)) {
|
|
26
|
-
if (textFilter) {
|
|
27
|
-
const filteredElement = selectElementByText(elements, textFilter.text, textFilter.mode);
|
|
28
|
-
if (!filteredElement) {
|
|
29
|
-
const textDisplay = Array.isArray(textFilter.text) ? textFilter.text.join(", ") : textFilter.text;
|
|
30
|
-
throw new Error(`No element found with text filter: "${textDisplay}" (mode: ${textFilter.mode})`);
|
|
31
|
-
}
|
|
32
|
-
targetElement = filteredElement;
|
|
33
|
-
} else {
|
|
34
|
-
targetElement = elements[0];
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
targetElement = elements;
|
|
38
|
-
}
|
|
39
|
-
await simulateClickElement(targetElement);
|
|
40
|
-
return { data: true };
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.log(error);
|
|
43
|
-
return {
|
|
44
|
-
hasError: true,
|
|
45
|
-
message: error instanceof Error ? error.message : "Unknown error in event-click handler",
|
|
46
|
-
data: false
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function selectElementByText(elements, textFilter, mode) {
|
|
51
|
-
for (const element of elements) {
|
|
52
|
-
const text = getElementText(element);
|
|
53
|
-
const textsToCheck = Array.isArray(textFilter) ? textFilter : [textFilter];
|
|
54
|
-
for (const filterText of textsToCheck) {
|
|
55
|
-
let matches = false;
|
|
56
|
-
switch (mode) {
|
|
57
|
-
case "exact":
|
|
58
|
-
matches = text === filterText;
|
|
59
|
-
break;
|
|
60
|
-
case "contains":
|
|
61
|
-
matches = text.includes(filterText);
|
|
62
|
-
break;
|
|
63
|
-
case "startsWith":
|
|
64
|
-
matches = text.startsWith(filterText);
|
|
65
|
-
break;
|
|
66
|
-
case "endsWith":
|
|
67
|
-
matches = text.endsWith(filterText);
|
|
68
|
-
break;
|
|
69
|
-
case "regex":
|
|
70
|
-
try {
|
|
71
|
-
const regex = new RegExp(filterText);
|
|
72
|
-
matches = regex.test(text);
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.warn("Invalid regex pattern:", filterText);
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
if (matches) {
|
|
80
|
-
return element;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
function getElementText(element) {
|
|
87
|
-
if (element.innerText) {
|
|
88
|
-
return element.innerText.trim();
|
|
89
|
-
}
|
|
90
|
-
if (element.textContent) {
|
|
91
|
-
return element.textContent.trim();
|
|
92
|
-
}
|
|
93
|
-
if (element instanceof HTMLInputElement && element.value) {
|
|
94
|
-
return element.value.trim();
|
|
95
|
-
}
|
|
96
|
-
const placeholder = element.getAttribute("placeholder");
|
|
97
|
-
if (placeholder) {
|
|
98
|
-
return placeholder.trim();
|
|
99
|
-
}
|
|
100
|
-
const title = element.getAttribute("title");
|
|
101
|
-
if (title) {
|
|
102
|
-
return title.trim();
|
|
103
|
-
}
|
|
104
|
-
const ariaLabel = element.getAttribute("aria-label");
|
|
105
|
-
if (ariaLabel) {
|
|
106
|
-
return ariaLabel.trim();
|
|
107
|
-
}
|
|
108
|
-
return "";
|
|
109
|
-
}
|
|
110
|
-
async function simulateClickElement(element) {
|
|
111
|
-
element.scrollIntoView({
|
|
112
|
-
behavior: "instant",
|
|
113
|
-
block: "center",
|
|
114
|
-
inline: "center"
|
|
115
|
-
});
|
|
116
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
117
|
-
if (element.focus) {
|
|
118
|
-
element.focus();
|
|
119
|
-
}
|
|
120
|
-
const rect = element.getBoundingClientRect();
|
|
121
|
-
const centerX = rect.left + rect.width / 2;
|
|
122
|
-
const centerY = rect.top + rect.height / 2;
|
|
123
|
-
try {
|
|
124
|
-
const response = await chrome.runtime.sendMessage({
|
|
125
|
-
type: "CDP_CLICK",
|
|
126
|
-
data: {
|
|
127
|
-
x: centerX,
|
|
128
|
-
y: centerY
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
if (response && !response.$isError) {
|
|
132
|
-
console.log("[EventClick] CDP click successful:", response);
|
|
133
|
-
} else {
|
|
134
|
-
throw new Error(response?.message || "CDP click failed");
|
|
135
|
-
}
|
|
136
|
-
} catch (error) {
|
|
137
|
-
console.error("[EventClick] CDP click failed, falling back to native click:", error);
|
|
138
|
-
if (element.click) {
|
|
139
|
-
element.click();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
143
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import z from "/vendor/.vite-deps-zod.js__v--13965f26.js";
|
|
2
|
-
export const FetchApiBlockSchema = z.object({
|
|
3
|
-
name: z.literal("fetch-api"),
|
|
4
|
-
url: z.string(),
|
|
5
|
-
method: z.enum(["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"]).optional(),
|
|
6
|
-
headers: z.record(z.string(), z.string()).optional(),
|
|
7
|
-
body: z.record(z.string(), z.any()).optional(),
|
|
8
|
-
timeout: z.number().min(0).optional(),
|
|
9
|
-
parseJson: z.boolean().optional(),
|
|
10
|
-
returnHeaders: z.boolean().optional()
|
|
11
|
-
});
|
|
12
|
-
export function validateFetchApiBlock(data) {
|
|
13
|
-
return FetchApiBlockSchema.parse(data);
|
|
14
|
-
}
|
|
15
|
-
export async function handlerFetchApi(data) {
|
|
16
|
-
try {
|
|
17
|
-
console.log("[FetchApiBlock] Sending API request to background:", data.url);
|
|
18
|
-
const response = await chrome.runtime.sendMessage({
|
|
19
|
-
type: "FETCH_API",
|
|
20
|
-
data: {
|
|
21
|
-
url: data.url,
|
|
22
|
-
method: data.method || "GET",
|
|
23
|
-
headers: data.headers || {},
|
|
24
|
-
body: data.body,
|
|
25
|
-
timeout: data.timeout || 3e4,
|
|
26
|
-
parseJson: data.parseJson ?? true,
|
|
27
|
-
// 기본값 true
|
|
28
|
-
returnHeaders: data.returnHeaders ?? false
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
if (response.$isError) {
|
|
32
|
-
return {
|
|
33
|
-
hasError: true,
|
|
34
|
-
message: response.message || "API request failed",
|
|
35
|
-
data: void 0
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
console.log("[FetchApiBlock] API request successful");
|
|
39
|
-
return {
|
|
40
|
-
data: response.data
|
|
41
|
-
};
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.error("[FetchApiBlock] API request error:", error);
|
|
44
|
-
return {
|
|
45
|
-
hasError: true,
|
|
46
|
-
message: error instanceof Error ? error.message : "Unknown error in API request",
|
|
47
|
-
data: void 0
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import z from "/vendor/.vite-deps-zod.js__v--13965f26.js";
|
|
2
|
-
import { BaseBlockSchema } from "/src/blocks/types.ts.js";
|
|
3
|
-
import { findElement } from "/src/content/elements/index.ts.js";
|
|
4
|
-
export const GetAttributeValueBlockSchema = BaseBlockSchema.extend({
|
|
5
|
-
name: z.literal("attribute-value"),
|
|
6
|
-
attributeName: z.string()
|
|
7
|
-
});
|
|
8
|
-
export function validateGetAttributeValueBlock(data) {
|
|
9
|
-
return GetAttributeValueBlockSchema.parse(data);
|
|
10
|
-
}
|
|
11
|
-
export async function handlerGetAttributeValue(data) {
|
|
12
|
-
try {
|
|
13
|
-
const { selector = "", attributeName, findBy = "cssSelector", option } = data;
|
|
14
|
-
if (!selector) {
|
|
15
|
-
throw new Error("Selector is required for attribute-value block");
|
|
16
|
-
}
|
|
17
|
-
if (!attributeName) {
|
|
18
|
-
throw new Error("Attribute name is required for attribute-value block");
|
|
19
|
-
}
|
|
20
|
-
const elements = await findElement({ selector, findBy, option });
|
|
21
|
-
if (!elements) {
|
|
22
|
-
return { data: null };
|
|
23
|
-
}
|
|
24
|
-
const result = Array.isArray(elements) ? elements.map((element) => element.getAttribute(attributeName)).filter((value) => value !== null) : elements.getAttribute(attributeName);
|
|
25
|
-
return { data: result };
|
|
26
|
-
} catch (error) {
|
|
27
|
-
return {
|
|
28
|
-
hasError: true,
|
|
29
|
-
message: error instanceof Error ? error.message : "Unknown error in attribute-value handler",
|
|
30
|
-
data: null
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import z from "/vendor/.vite-deps-zod.js__v--13965f26.js";
|
|
2
|
-
import { BaseBlockSchema } from "/src/blocks/types.ts.js";
|
|
3
|
-
import { findElement } from "/src/content/elements/index.ts.js";
|
|
4
|
-
import { CSSSelectorGenerator } from "/src/content/elements/utils/CSSSelectorGenerator.ts.js";
|
|
5
|
-
import { XPathGenerator } from "/src/content/elements/utils/XPathGenerator.ts.js";
|
|
6
|
-
export const GetElementDataBlockSchema = BaseBlockSchema.extend({
|
|
7
|
-
name: z.literal("get-element-data"),
|
|
8
|
-
includeText: z.boolean().optional(),
|
|
9
|
-
includeTags: z.boolean().optional(),
|
|
10
|
-
useTextContent: z.boolean().optional(),
|
|
11
|
-
regex: z.string().optional(),
|
|
12
|
-
prefixText: z.string().optional(),
|
|
13
|
-
suffixText: z.string().optional(),
|
|
14
|
-
attributes: z.array(z.string()).optional(),
|
|
15
|
-
includeSelector: z.boolean().optional(),
|
|
16
|
-
includeXPath: z.boolean().optional()
|
|
17
|
-
});
|
|
18
|
-
export function validateGetElementDataBlock(data) {
|
|
19
|
-
return GetElementDataBlockSchema.parse(data);
|
|
20
|
-
}
|
|
21
|
-
export async function handlerGetElementData(data) {
|
|
22
|
-
try {
|
|
23
|
-
const {
|
|
24
|
-
selector = "",
|
|
25
|
-
includeText = true,
|
|
26
|
-
includeTags = false,
|
|
27
|
-
useTextContent = false,
|
|
28
|
-
regex,
|
|
29
|
-
prefixText = "",
|
|
30
|
-
suffixText = "",
|
|
31
|
-
attributes = [],
|
|
32
|
-
includeSelector = false,
|
|
33
|
-
includeXPath = false,
|
|
34
|
-
findBy = "cssSelector",
|
|
35
|
-
option
|
|
36
|
-
} = data;
|
|
37
|
-
if (!selector) {
|
|
38
|
-
throw new Error("Selector is required for get-element-data block");
|
|
39
|
-
}
|
|
40
|
-
if (!includeText && attributes.length === 0) {
|
|
41
|
-
throw new Error("Either includeText must be true or attributes must be provided");
|
|
42
|
-
}
|
|
43
|
-
const elements = await findElement({ selector, findBy, option });
|
|
44
|
-
if (!elements) {
|
|
45
|
-
return { data: Array.isArray(elements) ? [] : {} };
|
|
46
|
-
}
|
|
47
|
-
const extractElementData = createElementDataExtractor(
|
|
48
|
-
includeText,
|
|
49
|
-
includeTags,
|
|
50
|
-
useTextContent,
|
|
51
|
-
regex,
|
|
52
|
-
prefixText,
|
|
53
|
-
suffixText,
|
|
54
|
-
attributes,
|
|
55
|
-
includeSelector,
|
|
56
|
-
includeXPath
|
|
57
|
-
);
|
|
58
|
-
if (Array.isArray(elements)) {
|
|
59
|
-
const elementsData = elements.map(extractElementData);
|
|
60
|
-
return { data: elementsData };
|
|
61
|
-
} else {
|
|
62
|
-
const elementData = extractElementData(elements);
|
|
63
|
-
return { data: elementData };
|
|
64
|
-
}
|
|
65
|
-
} catch (error) {
|
|
66
|
-
return {
|
|
67
|
-
hasError: true,
|
|
68
|
-
message: error instanceof Error ? error.message : "Unknown error in get-element-data handler",
|
|
69
|
-
data: {}
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
function createElementDataExtractor(includeText, includeTags, useTextContent, regex, prefixText = "", suffixText = "", attributes = [], includeSelector = false, includeXPath = false) {
|
|
74
|
-
return (element) => {
|
|
75
|
-
const result = {};
|
|
76
|
-
if (includeText) {
|
|
77
|
-
let text = "";
|
|
78
|
-
if (includeTags) {
|
|
79
|
-
text = element.innerHTML;
|
|
80
|
-
} else {
|
|
81
|
-
text = useTextContent ? element.textContent || "" : element.innerText || "";
|
|
82
|
-
}
|
|
83
|
-
if (regex) {
|
|
84
|
-
const regexPattern = new RegExp(regex, "g");
|
|
85
|
-
const matches = text.match(regexPattern);
|
|
86
|
-
text = matches ? matches.join(" ") : "";
|
|
87
|
-
}
|
|
88
|
-
if (text.trim()) {
|
|
89
|
-
text = prefixText + text.trim() + suffixText;
|
|
90
|
-
}
|
|
91
|
-
result.text = text;
|
|
92
|
-
}
|
|
93
|
-
if (attributes.length > 0) {
|
|
94
|
-
result.attributes = {};
|
|
95
|
-
attributes.forEach((attrName) => {
|
|
96
|
-
let attrValue = element.getAttribute(attrName);
|
|
97
|
-
if (attrValue === null) {
|
|
98
|
-
const childWithAttr = element.querySelector(`[${attrName}]`);
|
|
99
|
-
if (childWithAttr) {
|
|
100
|
-
attrValue = childWithAttr.getAttribute(attrName);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
result.attributes[attrName] = attrValue;
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
if (includeSelector) {
|
|
107
|
-
result.selector = CSSSelectorGenerator.generate(element);
|
|
108
|
-
}
|
|
109
|
-
if (includeXPath) {
|
|
110
|
-
result.xpath = XPathGenerator.generate(element);
|
|
111
|
-
}
|
|
112
|
-
return result;
|
|
113
|
-
};
|
|
114
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import z from "/vendor/.vite-deps-zod.js__v--13965f26.js";
|
|
2
|
-
import { BaseBlockSchema } from "/src/blocks/types.ts.js";
|
|
3
|
-
import { findElement } from "/src/content/elements/index.ts.js";
|
|
4
|
-
export const GetTextBlockSchema = BaseBlockSchema.extend({
|
|
5
|
-
name: z.literal("get-text"),
|
|
6
|
-
includeTags: z.boolean().optional(),
|
|
7
|
-
useTextContent: z.boolean().optional(),
|
|
8
|
-
regex: z.string().optional(),
|
|
9
|
-
prefixText: z.string().optional(),
|
|
10
|
-
suffixText: z.string().optional(),
|
|
11
|
-
filterEmpty: z.boolean().optional(),
|
|
12
|
-
scrollToCollect: z.boolean().optional(),
|
|
13
|
-
scrollDistance: z.number().optional(),
|
|
14
|
-
scrollWaitMs: z.number().optional(),
|
|
15
|
-
maxScrollAttempts: z.number().optional()
|
|
16
|
-
});
|
|
17
|
-
export function validateGetTextBlock(data) {
|
|
18
|
-
return GetTextBlockSchema.parse(data);
|
|
19
|
-
}
|
|
20
|
-
export async function handlerGetText(data) {
|
|
21
|
-
try {
|
|
22
|
-
const {
|
|
23
|
-
selector = "",
|
|
24
|
-
includeTags = false,
|
|
25
|
-
useTextContent = false,
|
|
26
|
-
regex,
|
|
27
|
-
prefixText = "",
|
|
28
|
-
suffixText = "",
|
|
29
|
-
findBy = "cssSelector",
|
|
30
|
-
option,
|
|
31
|
-
filterEmpty = true,
|
|
32
|
-
scrollToCollect = false,
|
|
33
|
-
scrollDistance = 500,
|
|
34
|
-
scrollWaitMs = 300,
|
|
35
|
-
maxScrollAttempts = 100
|
|
36
|
-
} = data;
|
|
37
|
-
if (!selector) {
|
|
38
|
-
throw new Error("Selector is required for get-text block");
|
|
39
|
-
}
|
|
40
|
-
if (scrollToCollect && option?.multiple) {
|
|
41
|
-
return await collectWithScroll({
|
|
42
|
-
selector,
|
|
43
|
-
findBy,
|
|
44
|
-
option,
|
|
45
|
-
includeTags,
|
|
46
|
-
useTextContent,
|
|
47
|
-
regex,
|
|
48
|
-
prefixText,
|
|
49
|
-
suffixText,
|
|
50
|
-
filterEmpty,
|
|
51
|
-
scrollDistance,
|
|
52
|
-
scrollWaitMs,
|
|
53
|
-
maxScrollAttempts
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
const elements = await findElement({ selector, findBy, option });
|
|
57
|
-
if (!elements) {
|
|
58
|
-
return { data: "" };
|
|
59
|
-
}
|
|
60
|
-
const extractText = createTextExtractor(
|
|
61
|
-
includeTags,
|
|
62
|
-
useTextContent,
|
|
63
|
-
regex,
|
|
64
|
-
prefixText,
|
|
65
|
-
suffixText
|
|
66
|
-
);
|
|
67
|
-
if (Array.isArray(elements)) {
|
|
68
|
-
const texts = elements.map(extractText);
|
|
69
|
-
const filteredTexts = filterEmpty ? texts.filter((text) => text.trim() !== "") : texts;
|
|
70
|
-
return { data: filteredTexts };
|
|
71
|
-
} else {
|
|
72
|
-
const text = extractText(elements);
|
|
73
|
-
return { data: text };
|
|
74
|
-
}
|
|
75
|
-
} catch (error) {
|
|
76
|
-
return {
|
|
77
|
-
hasError: true,
|
|
78
|
-
message: error instanceof Error ? error.message : "Unknown error in get-text handler",
|
|
79
|
-
data: ""
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async function collectWithScroll(params) {
|
|
84
|
-
const {
|
|
85
|
-
selector,
|
|
86
|
-
findBy,
|
|
87
|
-
option,
|
|
88
|
-
includeTags,
|
|
89
|
-
useTextContent,
|
|
90
|
-
regex,
|
|
91
|
-
prefixText,
|
|
92
|
-
suffixText,
|
|
93
|
-
filterEmpty,
|
|
94
|
-
scrollDistance,
|
|
95
|
-
scrollWaitMs,
|
|
96
|
-
maxScrollAttempts
|
|
97
|
-
} = params;
|
|
98
|
-
const extractText = createTextExtractor(includeTags, useTextContent, regex, prefixText, suffixText);
|
|
99
|
-
const collectedTexts = /* @__PURE__ */ new Set();
|
|
100
|
-
let scrollAttempts = 0;
|
|
101
|
-
let consecutiveNoNewData = 0;
|
|
102
|
-
const maxConsecutiveNoNewData = 5;
|
|
103
|
-
while (scrollAttempts < maxScrollAttempts) {
|
|
104
|
-
const elements = await findElement({ selector, findBy, option });
|
|
105
|
-
if (elements && Array.isArray(elements)) {
|
|
106
|
-
const beforeSize = collectedTexts.size;
|
|
107
|
-
elements.forEach((element) => {
|
|
108
|
-
const text = extractText(element);
|
|
109
|
-
if (!filterEmpty || text.trim() !== "") {
|
|
110
|
-
collectedTexts.add(text);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
const afterSize = collectedTexts.size;
|
|
114
|
-
if (afterSize === beforeSize) {
|
|
115
|
-
consecutiveNoNewData++;
|
|
116
|
-
if (consecutiveNoNewData >= maxConsecutiveNoNewData) {
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
} else {
|
|
120
|
-
consecutiveNoNewData = 0;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
const currentScrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
|
124
|
-
window.scrollBy({ top: scrollDistance, behavior: "auto" });
|
|
125
|
-
await new Promise((resolve) => setTimeout(resolve, scrollWaitMs));
|
|
126
|
-
const newScrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
|
127
|
-
if (newScrollTop === currentScrollTop) {
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
scrollAttempts++;
|
|
131
|
-
}
|
|
132
|
-
return { data: Array.from(collectedTexts) };
|
|
133
|
-
}
|
|
134
|
-
function createTextExtractor(includeTags, useTextContent, regex, prefixText = "", suffixText = "") {
|
|
135
|
-
return (element) => {
|
|
136
|
-
let text = "";
|
|
137
|
-
if (includeTags) {
|
|
138
|
-
text = element.innerHTML;
|
|
139
|
-
} else {
|
|
140
|
-
text = useTextContent ? element.textContent || "" : element.innerText || "";
|
|
141
|
-
}
|
|
142
|
-
if (regex) {
|
|
143
|
-
const regexPattern = new RegExp(regex, "g");
|
|
144
|
-
const matches = text.match(regexPattern);
|
|
145
|
-
text = matches ? matches.join(" ") : "";
|
|
146
|
-
}
|
|
147
|
-
if (text.trim()) {
|
|
148
|
-
text = prefixText + text.trim() + suffixText;
|
|
149
|
-
}
|
|
150
|
-
return text;
|
|
151
|
-
};
|
|
152
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { findElement } from "/src/content/elements/index.ts.js";
|
|
2
|
-
import { BaseBlockSchema } from "/src/blocks/types.ts.js";
|
|
3
|
-
import z from "/vendor/.vite-deps-zod.js__v--13965f26.js";
|
|
4
|
-
export const GetValueFormsBlockSchema = BaseBlockSchema.extend({
|
|
5
|
-
name: z.literal("get-value-form"),
|
|
6
|
-
type: z.enum(["text-field", "select", "checkbox"]).optional()
|
|
7
|
-
});
|
|
8
|
-
export function validateGetValueFormsBlock(data) {
|
|
9
|
-
return GetValueFormsBlockSchema.parse(data);
|
|
10
|
-
}
|
|
11
|
-
export async function handlerGetValueForm(data) {
|
|
12
|
-
try {
|
|
13
|
-
const { selector = "", type = "text-field", findBy = "cssSelector" } = data;
|
|
14
|
-
if (!selector) {
|
|
15
|
-
throw new Error("Selector is required for get-value-form block");
|
|
16
|
-
}
|
|
17
|
-
const element = await findElement({ selector, findBy, option: data.option });
|
|
18
|
-
if (!element) {
|
|
19
|
-
throw new Error("Form element not found");
|
|
20
|
-
}
|
|
21
|
-
const value = getFormValue(element, type);
|
|
22
|
-
return { data: value };
|
|
23
|
-
} catch (error) {
|
|
24
|
-
return {
|
|
25
|
-
hasError: true,
|
|
26
|
-
message: error instanceof Error ? error.message : "Unknown error in get-value-form handler",
|
|
27
|
-
data: null
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function getFormValue(element, type) {
|
|
32
|
-
switch (type) {
|
|
33
|
-
case "text-field":
|
|
34
|
-
if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement) {
|
|
35
|
-
return element.value;
|
|
36
|
-
}
|
|
37
|
-
break;
|
|
38
|
-
case "select":
|
|
39
|
-
if (element instanceof HTMLSelectElement) {
|
|
40
|
-
return element.value;
|
|
41
|
-
}
|
|
42
|
-
break;
|
|
43
|
-
case "checkbox":
|
|
44
|
-
if (element instanceof HTMLInputElement && element.type === "checkbox") {
|
|
45
|
-
return element.checked;
|
|
46
|
-
}
|
|
47
|
-
break;
|
|
48
|
-
default:
|
|
49
|
-
throw new Error(`Unsupported form element type: ${type}`);
|
|
50
|
-
}
|
|
51
|
-
throw new Error(`Invalid element type for ${type}`);
|
|
52
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import z from "/vendor/.vite-deps-zod.js__v--13965f26.js";
|
|
2
|
-
export const KeypressBlockSchema = z.object({
|
|
3
|
-
name: z.literal("keypress"),
|
|
4
|
-
key: z.string(),
|
|
5
|
-
code: z.string().optional(),
|
|
6
|
-
keyCode: z.number().optional(),
|
|
7
|
-
modifiers: z.array(z.enum(["Alt", "Control", "Meta", "Shift"])).optional()
|
|
8
|
-
});
|
|
9
|
-
export function validateKeypressBlock(data) {
|
|
10
|
-
return KeypressBlockSchema.parse(data);
|
|
11
|
-
}
|
|
12
|
-
export async function handlerKeypress(data) {
|
|
13
|
-
try {
|
|
14
|
-
const { key, code, keyCode, modifiers = [] } = data;
|
|
15
|
-
await simulateKeypress(key, code, keyCode, modifiers);
|
|
16
|
-
return { data: true };
|
|
17
|
-
} catch (error) {
|
|
18
|
-
console.log(error);
|
|
19
|
-
return {
|
|
20
|
-
hasError: true,
|
|
21
|
-
message: error instanceof Error ? error.message : "Unknown error in keypress handler",
|
|
22
|
-
data: false
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
async function simulateKeypress(key, code, keyCode, modifiers = []) {
|
|
27
|
-
try {
|
|
28
|
-
const response = await chrome.runtime.sendMessage({
|
|
29
|
-
type: "CDP_KEYPRESS",
|
|
30
|
-
data: {
|
|
31
|
-
key,
|
|
32
|
-
code: code || key,
|
|
33
|
-
keyCode: keyCode || getKeyCodeFromKey(key),
|
|
34
|
-
modifiers
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
if (response && !response.$isError) {
|
|
38
|
-
console.log("[Keypress] CDP keypress successful:", response);
|
|
39
|
-
} else {
|
|
40
|
-
throw new Error(response?.message || "CDP keypress failed");
|
|
41
|
-
}
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.error("[Keypress] CDP keypress failed, falling back to native dispatch:", error);
|
|
44
|
-
const keydownEvent = new KeyboardEvent("keydown", {
|
|
45
|
-
key,
|
|
46
|
-
code: code || key,
|
|
47
|
-
keyCode: keyCode || getKeyCodeFromKey(key),
|
|
48
|
-
bubbles: true,
|
|
49
|
-
cancelable: true,
|
|
50
|
-
...getModifierStates(modifiers)
|
|
51
|
-
});
|
|
52
|
-
const keyupEvent = new KeyboardEvent("keyup", {
|
|
53
|
-
key,
|
|
54
|
-
code: code || key,
|
|
55
|
-
keyCode: keyCode || getKeyCodeFromKey(key),
|
|
56
|
-
bubbles: true,
|
|
57
|
-
cancelable: true,
|
|
58
|
-
...getModifierStates(modifiers)
|
|
59
|
-
});
|
|
60
|
-
document.dispatchEvent(keydownEvent);
|
|
61
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
62
|
-
document.dispatchEvent(keyupEvent);
|
|
63
|
-
}
|
|
64
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
65
|
-
}
|
|
66
|
-
function getKeyCodeFromKey(key) {
|
|
67
|
-
const keyCodeMap = {
|
|
68
|
-
"Escape": 27,
|
|
69
|
-
"Enter": 13,
|
|
70
|
-
"Tab": 9,
|
|
71
|
-
"Backspace": 8,
|
|
72
|
-
"Delete": 46,
|
|
73
|
-
"ArrowUp": 38,
|
|
74
|
-
"ArrowDown": 40,
|
|
75
|
-
"ArrowLeft": 37,
|
|
76
|
-
"ArrowRight": 39,
|
|
77
|
-
"Space": 32,
|
|
78
|
-
" ": 32
|
|
79
|
-
};
|
|
80
|
-
return keyCodeMap[key] || 0;
|
|
81
|
-
}
|
|
82
|
-
function getModifierStates(modifiers) {
|
|
83
|
-
return {
|
|
84
|
-
altKey: modifiers.includes("Alt"),
|
|
85
|
-
ctrlKey: modifiers.includes("Control"),
|
|
86
|
-
metaKey: modifiers.includes("Meta"),
|
|
87
|
-
shiftKey: modifiers.includes("Shift")
|
|
88
|
-
};
|
|
89
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { findElement } from "/src/content/elements/index.ts.js";
|
|
2
|
-
import { BaseBlockSchema } from "/src/blocks/types.ts.js";
|
|
3
|
-
import z from "/vendor/.vite-deps-zod.js__v--13965f26.js";
|
|
4
|
-
export const SaveAssetsBlockSchema = BaseBlockSchema.extend({
|
|
5
|
-
name: z.literal("save-assets")
|
|
6
|
-
});
|
|
7
|
-
export function validateSaveAssetsBlock(data) {
|
|
8
|
-
return SaveAssetsBlockSchema.parse(data);
|
|
9
|
-
}
|
|
10
|
-
export async function handlerSaveAssets(data) {
|
|
11
|
-
try {
|
|
12
|
-
const { selector = "img, audio, video, source", findBy = "cssSelector", option } = data;
|
|
13
|
-
const elements = await findElement({ selector, findBy, option });
|
|
14
|
-
if (!elements || !Array.isArray(elements)) {
|
|
15
|
-
return { data: [] };
|
|
16
|
-
}
|
|
17
|
-
const assetUrls = [];
|
|
18
|
-
elements.forEach((element) => {
|
|
19
|
-
let src = "";
|
|
20
|
-
if (element instanceof HTMLImageElement || element instanceof HTMLAudioElement || element instanceof HTMLVideoElement || element instanceof HTMLSourceElement) {
|
|
21
|
-
src = element.src;
|
|
22
|
-
}
|
|
23
|
-
if (src && !assetUrls.includes(src)) {
|
|
24
|
-
assetUrls.push(src);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return { data: assetUrls };
|
|
28
|
-
} catch (error) {
|
|
29
|
-
return {
|
|
30
|
-
hasError: true,
|
|
31
|
-
message: error instanceof Error ? error.message : "Unknown error in save-assets handler",
|
|
32
|
-
data: null
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|