Skip to content

Commit

Permalink
feat(surge2egern): 优化转换速度
Browse files Browse the repository at this point in the history
  • Loading branch information
baranwang committed Nov 5, 2024
1 parent d65593b commit be34489
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-cobras-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@iringo/surge2egern": minor
---

优化转换速度
18 changes: 11 additions & 7 deletions packages/surge2egern/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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));

Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be34489

Please sign in to comment.