scordi-extension 1.14.6 → 1.14.8
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/assets/loading-page-1924caaa.js +51 -0
- package/dist/blocks/ClearValueFormBlock.d.ts +8 -8
- package/dist/blocks/DataExtractBlock.d.ts +2 -2
- package/dist/blocks/ElementExistsBlock.d.ts +8 -8
- package/dist/blocks/EventClickBlock.d.ts +12 -12
- package/dist/blocks/FetchApiBlock.d.ts +2 -2
- package/dist/blocks/GetAttributeValueBlock.d.ts +8 -8
- package/dist/blocks/GetElementDataBlock.d.ts +14 -14
- package/dist/blocks/GetTextBlock.d.ts +10 -10
- package/dist/blocks/GetValueFormBlock.d.ts +8 -8
- package/dist/blocks/SaveAssetsBlock.d.ts +8 -8
- package/dist/blocks/ScrollBlock.d.ts +8 -8
- package/dist/blocks/SetValueFormBlock.d.ts +8 -8
- package/dist/blocks/WaitForConditionBlock.d.ts +176 -0
- package/dist/blocks/WaitForConditionBlock.d.ts.map +1 -0
- package/dist/blocks/index.d.ts +232 -96
- package/dist/blocks/index.d.ts.map +1 -1
- package/dist/blocks/types.d.ts +25 -8
- package/dist/blocks/types.d.ts.map +1 -1
- package/dist/logo.png +0 -0
- package/dist/manifest.json +55 -0
- package/dist/public/logo.png +0 -0
- package/dist/sdk/index.cjs +4 -1
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +5569 -1437
- package/dist/sdk/types.d.ts +3 -3
- package/dist/sdk/types.d.ts.map +1 -1
- package/dist/service-worker-loader.js +3 -0
- package/dist/src/blocks/AiParseDataBlock.ts.js +101 -0
- package/dist/src/blocks/ClearValueFormBlock.ts.js +55 -0
- package/dist/src/blocks/DataExtractBlock.ts.js +28 -0
- package/dist/src/blocks/ElementExistsBlock.ts.js +26 -0
- package/dist/src/blocks/EventClickBlock.ts.js +143 -0
- package/dist/src/blocks/FetchApiBlock.ts.js +50 -0
- package/dist/src/blocks/GetAttributeValueBlock.ts.js +33 -0
- package/dist/src/blocks/GetElementDataBlock.ts.js +114 -0
- package/dist/src/blocks/GetTextBlock.ts.js +152 -0
- package/dist/src/blocks/GetValueFormBlock.ts.js +52 -0
- package/dist/src/blocks/KeypressBlock.ts.js +89 -0
- package/dist/src/blocks/SaveAssetsBlock.ts.js +35 -0
- package/dist/src/blocks/ScrollBlock.ts.js +111 -0
- package/dist/src/blocks/SetValueFormBlock.ts.js +56 -0
- package/dist/src/blocks/WaitBlock.ts.js +24 -0
- package/dist/src/blocks/WaitForConditionBlock.ts.js +187 -0
- package/dist/src/blocks/index.ts.js +174 -0
- package/dist/src/blocks/types.ts.js +12 -0
- package/dist/src/content/components/ConfirmationUI.tsx.js +236 -0
- package/dist/src/content/elements/finders/CssSelector.ts.js +51 -0
- package/dist/src/content/elements/finders/ElementSelector.ts.js +20 -0
- package/dist/src/content/elements/finders/IframeSelector.ts.js +32 -0
- package/dist/src/content/elements/finders/ShadowDOMSelector.ts.js +38 -0
- package/dist/src/content/elements/finders/XPathFinder.ts.js +32 -0
- package/dist/src/content/elements/index.ts.js +26 -0
- package/dist/src/content/elements/utils/CSSSelectorGenerator.ts.js +72 -0
- package/dist/src/content/elements/utils/XPathGenerator.ts.js +62 -0
- package/dist/src/content/handler/ExternalMessageHandler.ts.js +78 -0
- package/dist/src/content/handler/InternalMessageHandler.ts.js +18 -0
- package/dist/src/content/kernel/MessageKernel.ts.js +83 -0
- package/dist/src/content/main.tsx-loader.js +22 -0
- package/dist/src/content/main.tsx.js +27 -0
- package/dist/src/content/utils/index.ts.js +1 -0
- package/dist/src/content/utils/synchronizedLock.ts.js +35 -0
- package/dist/src/popup/index.html +12 -0
- package/dist/src/types/internal-messages.ts.js +15 -0
- package/dist/vendor/.vite-deps-chunk-2TUXWMP5.js__v--9054997c.js +45 -0
- package/dist/vendor/.vite-deps-chunk-2TUXWMP5.js__v--e2a1f584.js +45 -0
- package/dist/vendor/.vite-deps-chunk-EL3BNLGW.js__v--e2a1f584.js +975 -0
- package/dist/vendor/.vite-deps-chunk-QIBDMRD4.js__v--9054997c.js +4158 -0
- package/dist/vendor/.vite-deps-chunk-QIBDMRD4.js__v--e2a1f584.js +4158 -0
- package/dist/vendor/.vite-deps-chunk-XHY3JSIG.js__v--e2a1f584.js +280 -0
- package/dist/vendor/.vite-deps-jsonata.js__v--d602c657.js +5761 -0
- package/dist/vendor/.vite-deps-jsonata.js__v--e2a1f584.js +5761 -0
- package/dist/vendor/.vite-deps-react-dom.js__v--e2a1f584.js +6 -0
- package/dist/vendor/.vite-deps-react-dom_client.js__v--e2a1f584.js +18108 -0
- package/dist/vendor/.vite-deps-react.js__v--e2a1f584.js +5 -0
- package/dist/vendor/.vite-deps-react_jsx-dev-runtime.js__v--e2a1f584.js +281 -0
- package/dist/vendor/.vite-deps-zod.js__v--9e0f4cc1.js +219 -0
- package/dist/vendor/.vite-deps-zod.js__v--e2a1f584.js +219 -0
- package/dist/vendor/crx-client-port.js +66 -0
- package/dist/vendor/crx-client-preamble.js +4 -0
- package/dist/vendor/react-refresh.js +670 -0
- package/dist/vendor/vite-client.js +1134 -0
- package/dist/vendor/vite-dist-client-env.mjs.js +24 -0
- package/dist/vendor/webcomponents-custom-elements.js +47 -0
- package/package.json +1 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import z from "/vendor/.vite-deps-zod.js__v--e2a1f584.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
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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--e2a1f584.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
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import z from "/vendor/.vite-deps-zod.js__v--e2a1f584.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
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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--e2a1f584.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
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import z from "/vendor/.vite-deps-zod.js__v--e2a1f584.js";
|
|
2
|
+
import { BaseBlockSchema } from "/src/blocks/types.ts.js";
|
|
3
|
+
import { findElement } from "/src/content/elements/index.ts.js";
|
|
4
|
+
export const ScrollBlockSchema = BaseBlockSchema.extend({
|
|
5
|
+
name: z.literal("scroll"),
|
|
6
|
+
scrollType: z.enum(["toElement", "toBottom", "byDistance", "untilLoaded"]).optional(),
|
|
7
|
+
distance: z.number().optional(),
|
|
8
|
+
behavior: z.enum(["auto", "smooth"]).optional(),
|
|
9
|
+
maxScrolls: z.number().optional(),
|
|
10
|
+
waitAfterScroll: z.number().optional()
|
|
11
|
+
});
|
|
12
|
+
export function validateScrollBlock(data) {
|
|
13
|
+
return ScrollBlockSchema.parse(data);
|
|
14
|
+
}
|
|
15
|
+
export async function handlerScroll(data) {
|
|
16
|
+
try {
|
|
17
|
+
const {
|
|
18
|
+
selector = "",
|
|
19
|
+
scrollType = "toBottom",
|
|
20
|
+
distance = 500,
|
|
21
|
+
behavior = "smooth",
|
|
22
|
+
maxScrolls = 50,
|
|
23
|
+
waitAfterScroll = 300,
|
|
24
|
+
findBy = "cssSelector",
|
|
25
|
+
option
|
|
26
|
+
} = data;
|
|
27
|
+
switch (scrollType) {
|
|
28
|
+
case "toElement":
|
|
29
|
+
if (!selector) {
|
|
30
|
+
throw new Error("Selector is required for toElement scroll type");
|
|
31
|
+
}
|
|
32
|
+
return await scrollToElement(selector, findBy, option, behavior);
|
|
33
|
+
case "toBottom":
|
|
34
|
+
return await scrollToBottom(behavior, waitAfterScroll);
|
|
35
|
+
case "byDistance":
|
|
36
|
+
return await scrollByDistance(distance, behavior);
|
|
37
|
+
case "untilLoaded":
|
|
38
|
+
return await scrollUntilLoaded(maxScrolls, distance, behavior, waitAfterScroll);
|
|
39
|
+
default:
|
|
40
|
+
throw new Error(`Unknown scroll type: ${scrollType}`);
|
|
41
|
+
}
|
|
42
|
+
} catch (error) {
|
|
43
|
+
return {
|
|
44
|
+
hasError: true,
|
|
45
|
+
message: error instanceof Error ? error.message : "Unknown error in scroll handler",
|
|
46
|
+
data: false
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function scrollToElement(selector, findBy, option, behavior) {
|
|
51
|
+
const element = await findElement({ selector, findBy, option });
|
|
52
|
+
if (!element) {
|
|
53
|
+
return {
|
|
54
|
+
hasError: true,
|
|
55
|
+
message: "Element not found for scrolling",
|
|
56
|
+
data: false
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const targetElement = Array.isArray(element) ? element[0] : element;
|
|
60
|
+
targetElement.scrollIntoView({ behavior, block: "center" });
|
|
61
|
+
return { data: true };
|
|
62
|
+
}
|
|
63
|
+
async function scrollToBottom(behavior, waitAfterScroll) {
|
|
64
|
+
let lastHeight = document.body.scrollHeight;
|
|
65
|
+
let attempts = 0;
|
|
66
|
+
const maxAttempts = 50;
|
|
67
|
+
while (attempts < maxAttempts) {
|
|
68
|
+
window.scrollTo({
|
|
69
|
+
top: document.body.scrollHeight,
|
|
70
|
+
behavior
|
|
71
|
+
});
|
|
72
|
+
await new Promise((resolve) => setTimeout(resolve, waitAfterScroll));
|
|
73
|
+
const newHeight = document.body.scrollHeight;
|
|
74
|
+
if (newHeight === lastHeight) {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
lastHeight = newHeight;
|
|
78
|
+
attempts++;
|
|
79
|
+
}
|
|
80
|
+
return { data: true };
|
|
81
|
+
}
|
|
82
|
+
async function scrollByDistance(distance, behavior) {
|
|
83
|
+
window.scrollBy({
|
|
84
|
+
top: distance,
|
|
85
|
+
behavior
|
|
86
|
+
});
|
|
87
|
+
return { data: true };
|
|
88
|
+
}
|
|
89
|
+
async function scrollUntilLoaded(maxScrolls, distance, behavior, waitAfterScroll) {
|
|
90
|
+
let scrollCount = 0;
|
|
91
|
+
let lastHeight = document.body.scrollHeight;
|
|
92
|
+
while (scrollCount < maxScrolls) {
|
|
93
|
+
window.scrollBy({
|
|
94
|
+
top: distance,
|
|
95
|
+
behavior
|
|
96
|
+
// Use provided behavior
|
|
97
|
+
});
|
|
98
|
+
await new Promise((resolve) => setTimeout(resolve, waitAfterScroll));
|
|
99
|
+
const newHeight = document.body.scrollHeight;
|
|
100
|
+
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
|
101
|
+
const windowHeight = window.innerHeight;
|
|
102
|
+
if (scrollTop + windowHeight >= newHeight - 10) {
|
|
103
|
+
if (newHeight === lastHeight) {
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
lastHeight = newHeight;
|
|
108
|
+
scrollCount++;
|
|
109
|
+
}
|
|
110
|
+
return { data: true };
|
|
111
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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--e2a1f584.js";
|
|
4
|
+
export const SetValueFormsBlockSchema = BaseBlockSchema.extend({
|
|
5
|
+
name: z.literal("set-value-form"),
|
|
6
|
+
setValue: z.string(),
|
|
7
|
+
type: z.enum(["text-field", "select", "checkbox"]).optional()
|
|
8
|
+
});
|
|
9
|
+
export function validateSetValueFormsBlock(data) {
|
|
10
|
+
return SetValueFormsBlockSchema.parse(data);
|
|
11
|
+
}
|
|
12
|
+
export async function handlerSetValueForm(data) {
|
|
13
|
+
try {
|
|
14
|
+
const { selector = "", setValue, type = "text-field", findBy = "cssSelector" } = data;
|
|
15
|
+
if (!selector) {
|
|
16
|
+
throw new Error("Selector is required for set-value-form block");
|
|
17
|
+
}
|
|
18
|
+
const element = await findElement({ selector, findBy, option: data.option });
|
|
19
|
+
if (!element) {
|
|
20
|
+
throw new Error("Form element not found");
|
|
21
|
+
}
|
|
22
|
+
setFormValue(element, setValue, type);
|
|
23
|
+
return { data: "Form element updated successfully" };
|
|
24
|
+
} catch (error) {
|
|
25
|
+
return {
|
|
26
|
+
hasError: true,
|
|
27
|
+
message: error instanceof Error ? error.message : "Unknown error in set-value-form handler",
|
|
28
|
+
data: null
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function setFormValue(element, value, type) {
|
|
33
|
+
switch (type) {
|
|
34
|
+
case "text-field":
|
|
35
|
+
if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement) {
|
|
36
|
+
element.value = value;
|
|
37
|
+
element.dispatchEvent(new Event("input", { bubbles: true }));
|
|
38
|
+
element.dispatchEvent(new Event("change", { bubbles: true }));
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
case "select":
|
|
42
|
+
if (element instanceof HTMLSelectElement) {
|
|
43
|
+
element.value = value;
|
|
44
|
+
element.dispatchEvent(new Event("change", { bubbles: true }));
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
case "checkbox":
|
|
48
|
+
if (element instanceof HTMLInputElement && element.type === "checkbox") {
|
|
49
|
+
element.checked = value === "true" || value === "checked";
|
|
50
|
+
element.dispatchEvent(new Event("change", { bubbles: true }));
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
throw new Error(`Unsupported form element type: ${type}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import z from "/vendor/.vite-deps-zod.js__v--e2a1f584.js";
|
|
2
|
+
export const WaitBlockSchema = z.object({
|
|
3
|
+
name: z.literal("wait"),
|
|
4
|
+
duration: z.number().min(0)
|
|
5
|
+
});
|
|
6
|
+
export function validateWaitBlock(data) {
|
|
7
|
+
return WaitBlockSchema.parse(data);
|
|
8
|
+
}
|
|
9
|
+
export async function handlerWait(data) {
|
|
10
|
+
try {
|
|
11
|
+
const { duration } = data;
|
|
12
|
+
console.log(`[Wait] Waiting for ${duration}ms...`);
|
|
13
|
+
await new Promise((resolve) => setTimeout(resolve, duration));
|
|
14
|
+
console.log(`[Wait] Wait completed after ${duration}ms`);
|
|
15
|
+
return { data: true };
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.log(error);
|
|
18
|
+
return {
|
|
19
|
+
hasError: true,
|
|
20
|
+
message: error instanceof Error ? error.message : "Unknown error in wait handler",
|
|
21
|
+
data: false
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|