MCPcopy
hub / github.com/ocsjs/ocsjs / domSearch

Function domSearch

packages/core/src/core/utils/dom.ts:9–28  ·  view source on GitHub ↗
(
	/** 搜索构造器 */
	wrapper: E,
	root: HTMLElement | Document = window.document
)

Source from the content-addressed store, hash-verified

7 * @returns
8 */
9export function domSearch<E extends RawElements>(
10 /** 搜索构造器 */
11 wrapper: E,
12 root: HTMLElement | Document = window.document
13): SearchedElements<E, HTMLElement | null> {
14 const obj = Object.create({});
15 Reflect.ownKeys(wrapper).forEach((key) => {
16 const item = wrapper[key.toString()];
17 Reflect.set(
18 obj,
19 key,
20 typeof item === 'string'
21 ? root.querySelector(item)
22 : typeof item === 'function'
23 ? item(root)
24 : item.map((fun) => fun(root))
25 );
26 });
27 return obj;
28}
29
30/**
31 * 元素搜索

Callers 3

searchJobElementFunction · 0.90
fixedVideoProgressFunction · 0.90
mediaFunction · 0.90

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected