Last active
May 3, 2024 07:14
-
-
Save ZiTAL/7795b22a84b64482466e14f15182fb87 to your computer and use it in GitHub Desktop.
openttd: automatic translate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
install: | |
npm install prompt-sync --save-dev | |
npm install testcafe --save-dev | |
create: | |
env.json with github credentials: {user: user, passwd: passwd} | |
exec: | |
npx testcafe firefox:headless porru.js | |
TODO: edit input and submit fields selectors | |
*/ | |
let prompt = require('prompt-sync')(); | |
const fs = require('fs'); | |
const { Selector } = require('testcafe'); | |
const env = JSON.parse(fs.readFileSync('env.json', 'utf-8')) | |
const USER = env.user | |
const PASSWD = env.passwd | |
let input = fs.readFileSync('input.str', 'utf8'); | |
let words = []; | |
let lines = input.split(/\n/); | |
lines.forEach(function(line) | |
{ | |
let m = line.match(/(STR_[^\s]+)\s+:([^$]+)$/); | |
if(m) | |
words.push({key: m[1], value: m[2]}); | |
}); | |
fixture('porru').page("https://translator.openttd.org/"); | |
test('porru hack', async t => | |
{ | |
await t.resizeWindow(1920, 1080) | |
const login = await Selector('a[href="/login?redirect=/"]') | |
await t.expect(login.exists).ok({ timeout: 2500 }) | |
await t.click(login) | |
const login_field = await Selector('#login_field') | |
await t.expect(login_field.exists).ok({ timeout: 2500 }) | |
await t.selectText(login_field).pressKey('delete'); | |
await t.typeText(login_field, USER); | |
const password = await Selector('#password') | |
await t.expect(password.exists).ok({ timeout: 2500 }) | |
await t.selectText(password).pressKey('delete'); | |
await t.typeText(password, PASSWD); | |
const commit = await Selector('input[name="commit"]') | |
await t.expect(commit.exists).ok({ timeout: 2500 }) | |
await t.click(commit) | |
const sms = await Selector('button[type="submit"]') | |
await t.expect(sms.exists).ok({ timeout: 2500 }) | |
await t.click(sms) | |
let token = prompt('Insert TOKEN:') | |
const sms_totp = await Selector('#sms_totp') | |
await t.expect(sms_totp.exists).ok({ timeout: 15000 }) | |
await t.typeText(sms_totp, token); | |
await t.wait(5000); | |
for(let i=0; i<words.length; i++) | |
{ | |
console.log(`${words[i].key}: ${words[i].value}`) | |
await t.navigateTo(`https://translator.openttd.org/string/openttd-master/eu_ES/${words[i].key}`); | |
let input = await Selector('#text_') | |
await t.expect(input.exists).ok({ timeout: 2500 }) | |
await t.selectTextAreaContent(input).pressKey('delete'); | |
await t.typeText(input, words[i].value); | |
let submit = await Selector('input[type="submit"]') | |
await t.expect(submit.exists).ok({ timeout: 15000 }) | |
//await t.selectText(app_totp).pressKey('delete'); | |
await t.click(submit) | |
await t.wait(5000); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment