ectrol 0.0.2 → 0.0.3

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/index.d.mts CHANGED
@@ -119,6 +119,74 @@ declare class ElementHandle {
119
119
  * - 返回扩展的 DOMRect 信息并包含元素中心点坐标。
120
120
  */
121
121
  getBoundingClientRect(timeout?: number): Promise<IBoundingClientRect | null>;
122
+ /**
123
+ * 选择下拉框选项。
124
+ * @param value 选项的值
125
+ * @returns
126
+ */
127
+ selectOption(value: string): Promise<any>;
128
+ /**
129
+ * 获取元素的 HTML 内容。
130
+ */
131
+ innerHTML(): Promise<any>;
132
+ /**
133
+ * 获取元素的文本内容。
134
+ */
135
+ innerText(): Promise<any>;
136
+ /**
137
+ * 获取元素的文本内容。
138
+ * @returns 元素的文本内容
139
+ */
140
+ textContent(): Promise<any>;
141
+ /**
142
+ * 获取元素的输入值。
143
+ * @returns 元素的输入值
144
+ */
145
+ inputValue(): Promise<any>;
146
+ /**
147
+ * 获取元素的选中状态。
148
+ * @returns 元素的选中状态
149
+ */
150
+ isChecked(): Promise<any>;
151
+ /**
152
+ * 获取元素的禁用状态。
153
+ * @returns 元素的禁用状态
154
+ */
155
+ isDisabled(): Promise<any>;
156
+ /**
157
+ * 获取元素的可见状态。
158
+ * @returns 元素的可见状态
159
+ */
160
+ isVisible(): Promise<any>;
161
+ /**
162
+ * 获取元素的可用状态。
163
+ * @returns 元素的可用状态
164
+ */
165
+ isEnabled(): Promise<any>;
166
+ /**
167
+ * 获取元素的可编辑状态。
168
+ * @returns 元素的可编辑状态
169
+ */
170
+ isEditable(): Promise<any>;
171
+ /**
172
+ * 获取元素的隐藏状态。
173
+ * @returns 元素的隐藏状态
174
+ */
175
+ isHidden(): Promise<any>;
176
+ /**
177
+ * 选中元素的文本内容。
178
+ */
179
+ selectText(options: {
180
+ timeout?: number;
181
+ }): Promise<any>;
182
+ /**
183
+ * 取消选中复选框或单选框。
184
+ * @param options 选项
185
+ * @returns
186
+ */
187
+ uncheck(options?: {
188
+ timeout?: number;
189
+ }): Promise<any>;
122
190
  }
123
191
  //#endregion
124
192
  //#region src/localStorage.d.ts
package/dist/index.mjs CHANGED
@@ -286,6 +286,206 @@ var ElementHandle = class {
286
286
  })()
287
287
  `);
288
288
  }
289
+ /**
290
+ * 选择下拉框选项。
291
+ * @param value 选项的值
292
+ * @returns
293
+ */
294
+ async selectOption(value) {
295
+ return this.contents.executeJavaScript(`
296
+ (function() {
297
+ const target = ${this._getElement()};
298
+ if (!target) return null;
299
+
300
+ // 验证元素是否为选择框
301
+ if (target.element.tagName !== 'SELECT') return null;
302
+
303
+ target.element.value = ${JSON.stringify(value)};
304
+ target.element.dispatchEvent(new Event('change', { bubbles: true }));
305
+ })()
306
+ `);
307
+ }
308
+ /**
309
+ * 获取元素的 HTML 内容。
310
+ */
311
+ async innerHTML() {
312
+ return this.contents.executeJavaScript(`
313
+ (function() {
314
+ const target = ${this._getElement()};
315
+ if (!target) return null;
316
+
317
+ return target.element.innerHTML;
318
+ })()
319
+ `);
320
+ }
321
+ /**
322
+ * 获取元素的文本内容。
323
+ */
324
+ async innerText() {
325
+ return this.contents.executeJavaScript(`
326
+ (function() {
327
+ const target = ${this._getElement()};
328
+ if (!target) return null;
329
+
330
+ return target.element.innerText;
331
+ })()
332
+ `);
333
+ }
334
+ /**
335
+ * 获取元素的文本内容。
336
+ * @returns 元素的文本内容
337
+ */
338
+ async textContent() {
339
+ return this.contents.executeJavaScript(`
340
+ (function() {
341
+ const target = ${this._getElement()};
342
+ if (!target) return null;
343
+
344
+ return target.element.textContent;
345
+ })()
346
+ `);
347
+ }
348
+ /**
349
+ * 获取元素的输入值。
350
+ * @returns 元素的输入值
351
+ */
352
+ async inputValue() {
353
+ return this.contents.executeJavaScript(`
354
+ (function() {
355
+ const target = ${this._getElement()};
356
+ if (!target) return null;
357
+
358
+ // 验证输入框是否是文本类型
359
+ if (target.element.tagName !== 'INPUT' && target.element.tagName !== 'TEXTAREA' && !target.element.isContentEditable) return null;
360
+
361
+ return target.element.value;
362
+ })()
363
+ `);
364
+ }
365
+ /**
366
+ * 获取元素的选中状态。
367
+ * @returns 元素的选中状态
368
+ */
369
+ async isChecked() {
370
+ return this.contents.executeJavaScript(`
371
+ (function() {
372
+ const target = ${this._getElement()};
373
+ if (!target) return null;
374
+
375
+ // 验证输入框是否是复选框或单选框
376
+ if (target.element.tagName !== 'INPUT' || target.element.type !== 'checkbox' && target.element.type !== 'radio') return null;
377
+
378
+ return target.element.checked;
379
+ })()
380
+ `);
381
+ }
382
+ /**
383
+ * 获取元素的禁用状态。
384
+ * @returns 元素的禁用状态
385
+ */
386
+ async isDisabled() {
387
+ return this.contents.executeJavaScript(`
388
+ (function() {
389
+ const target = ${this._getElement()};
390
+ if (!target) return null;
391
+
392
+ return target.element.disabled;
393
+ })()
394
+ `);
395
+ }
396
+ /**
397
+ * 获取元素的可见状态。
398
+ * @returns 元素的可见状态
399
+ */
400
+ async isVisible() {
401
+ return this.contents.executeJavaScript(`
402
+ (function() {
403
+ const target = ${this._getElement()};
404
+ if (!target) return null;
405
+
406
+ return target.element.offsetParent !== null;
407
+ })()
408
+ `);
409
+ }
410
+ /**
411
+ * 获取元素的可用状态。
412
+ * @returns 元素的可用状态
413
+ */
414
+ async isEnabled() {
415
+ return this.contents.executeJavaScript(`
416
+ (function() {
417
+ const target = ${this._getElement()};
418
+ if (!target) return null;
419
+
420
+ return !target.element.disabled;
421
+ })()
422
+ `);
423
+ }
424
+ /**
425
+ * 获取元素的可编辑状态。
426
+ * @returns 元素的可编辑状态
427
+ */
428
+ async isEditable() {
429
+ return this.contents.executeJavaScript(`
430
+ (function() {
431
+ const target = ${this._getElement()};
432
+ if (!target) return null;
433
+
434
+ return target.element.isContentEditable;
435
+ })()
436
+ `);
437
+ }
438
+ /**
439
+ * 获取元素的隐藏状态。
440
+ * @returns 元素的隐藏状态
441
+ */
442
+ async isHidden() {
443
+ return this.contents.executeJavaScript(`
444
+ (function() {
445
+ const target = ${this._getElement()};
446
+ if (!target) return null;
447
+
448
+ return target.element.offsetParent === null;
449
+ })()
450
+ `);
451
+ }
452
+ /**
453
+ * 选中元素的文本内容。
454
+ */
455
+ async selectText(options) {
456
+ return this.contents.executeJavaScript(`
457
+ (function() {
458
+ const target = ${this._getElement(options.timeout)};
459
+ if (!target) return null;
460
+
461
+ // 选中元素的文本内容
462
+ const selection = window.getSelection();
463
+ const range = document.createRange();
464
+ range.selectNodeContents(target.element);
465
+ selection.removeAllRanges();
466
+ selection.addRange(range);
467
+ })()
468
+ `);
469
+ }
470
+ /**
471
+ * 取消选中复选框或单选框。
472
+ * @param options 选项
473
+ * @returns
474
+ */
475
+ async uncheck(options) {
476
+ return this.contents.executeJavaScript(`
477
+ (function() {
478
+ const target = ${this._getElement(options?.timeout)};
479
+ if (!target) return null;
480
+
481
+ // 验证输入框是否是复选框或单选框
482
+ if (target.element.tagName !== 'INPUT' || target.element.type !== 'checkbox' && target.element.type !== 'radio') return null;
483
+
484
+ target.element.checked = false;
485
+ target.element.dispatchEvent(new Event('change', { bubbles: true }));
486
+ })()
487
+ `);
488
+ }
289
489
  };
290
490
  var element_default = ElementHandle;
291
491
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ectrol",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "description": "一个基于 Electron WebContents 的轻量级自动化助手,用于在你的应用内对网页内容进行交互(点击、输入、聚焦、键盘事件等)。",
6
6
  "author": "Cee Vee X <ceeveex@hotmail.com>",
7
7
  "license": "MIT",