forked from orgtwentyfive/evo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate-data.ts
56 lines (54 loc) · 2.17 KB
/
translate-data.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import puppeteer from 'puppeteer-extra'
import StealthPlugin from 'puppeteer-extra-plugin-stealth'
import { sleep } from './tools'
import json from './data.json'
puppeteer.use(StealthPlugin())
let data = json as any[]
let i = 0
async function main() {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
})
const page = await browser.newPage()
await page.goto('https://www.deepl.com/en/login/', { waitUntil: 'networkidle0' })
await page.type('[data-testid="menu-login-username"]', 'chitorogcostea@gmail.com')
await page.type('[data-testid="menu-login-password"]', '24PT,5sge4MhUHy')
page.click('[data-testid="menu-login-submit"]')
await page.waitForNavigation({ waitUntil: 'networkidle0' })
console.log('Logged in!')
await page.evaluate(() => {
return navigator.clipboard.readText()
})
for (const item of data) {
if (item.toIndexDataEn) continue
await page.evaluate(async (text: string) => {
//@ts-ignore
const el = document.querySelector('[data-testid="translator-source-input"] > div')!
el.innerHTML = text
await new Promise((resolve) => setTimeout(resolve, 1000))
el.dispatchEvent(new Event('input', { bubbles: true }))
}, item.toIndexData)
await page.waitForNetworkIdle({ idleTime: 5_000, timeout: 20_000 })
await page.evaluate(() => {
//@ts-ignore
document.querySelector('[data-testid="translator-target-toolbar-copy"]').click()
})
const translate = await page.evaluate(() => {
return navigator.clipboard.readText()
})
console.log(translate.slice(0, 100))
console.log(i++)
}
// await page.keyboard.press('Enter')
// await page.click('[data-testid="translator-target-lang-btn"]')
// await sleep(1000)
// await page.keyboard.type('en')
// await sleep(1000)
// await page.keyboard.press('Enter')
// console.log('Logged in!')
// await sleep(100_000)
await sleep(100_000)
}
main().then(() => console.log('Done!'))