diff --git a/.changeset/wicked-cobras-rhyme.md b/.changeset/wicked-cobras-rhyme.md new file mode 100644 index 0000000..611ed32 --- /dev/null +++ b/.changeset/wicked-cobras-rhyme.md @@ -0,0 +1,5 @@ +--- +"@iringo/surge2egern": minor +--- + +优化转换速度 diff --git a/packages/surge2egern/src/index.ts b/packages/surge2egern/src/index.ts index 1a5074a..892b89e 100644 --- a/packages/surge2egern/src/index.ts +++ b/packages/surge2egern/src/index.ts @@ -16,7 +16,7 @@ export class Surge2Egern { this.#browser = await puppeteer.launch(); this.#page = await this.#browser.newPage(); - await this.#page.goto('https://gen.egernapp.com/'); + await this.#page.goto('https://gen.egernapp.com/', { waitUntil: 'networkidle0' }); } async #findElement(title: string) { @@ -57,12 +57,16 @@ export class Surge2Egern { const { inputElement, outputElement } = await this.#findElement(title); // 清空输入框的内容 - await this.#page.evaluate((input) => { - input.value = ''; - }, inputElement); - - // 输入新的内容 - await inputElement.type(text); + await this.#page.evaluate( + (input, value) => { + input.value = value; + input.dispatchEvent(new Event('input', { bubbles: true })); + }, + inputElement, + text, + ); + + await inputElement.type('\n'); await new Promise((resolve) => setTimeout(resolve, 500)); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 88371c4..ae4ad39 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -463,6 +463,9 @@ importers: packages/surge2egern: dependencies: + grapheme-splitter: + specifier: ^1.0.4 + version: 1.0.4 ora: specifier: ^5.4.1 version: 5.4.1 @@ -3484,6 +3487,9 @@ packages: graceful-fs@4.2.11: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} + grapheme-splitter@1.0.4: + resolution: {integrity: sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==} + gray-matter@4.0.3: resolution: {integrity: sha512-5v6yZd4JK3eMI3FqqCouswVqwugaA9r4dNZB1wwcmrD02QkV5H0y7XBQW8QwQqEaZY1pM9aqORSORhJRdNK44Q==} engines: {node: '>=6.0'} @@ -9345,6 +9351,8 @@ snapshots: graceful-fs@4.2.11: {} + grapheme-splitter@1.0.4: {} + gray-matter@4.0.3: dependencies: js-yaml: 3.14.1