@yiero/gmlib
Version:
GM Lib for Tampermonkey/ScriptCat
31 lines (30 loc) • 920 B
TypeScript
import type { IElementWaiterOption } from './elementWaiter';
/**
* 元素获取器选项
*
* 与 IElementWaiterOption 结构相同
*/
export type IElementGetterOption = IElementWaiterOption;
/**
* 通过定时器轮询获取页面元素
*
* 与 elementWaiter 的区别:仅使用定时器轮询,不使用 MutationObserver
*
* @param selector CSS 选择器
* @param options 配置选项(可选)
* @returns Promise<T> 匹配的 HTMLElement 元素
*
* @example
* ```ts
* // 获取 id 为 'app' 的元素
* const appElement = await elementGetter('#app');
* console.log(appElement);
*
* // 指定父容器和超时时间
* const element = await elementGetter('.item', {
* parent: document.querySelector('.container'),
* timeoutPerSecond: 10
* });
* ```
*/
export declare function elementGetter<T extends HTMLElement>(selector: string, options?: Partial<IElementGetterOption>): Promise<T>;