2020-10-14 03:37:03 +03:00
|
|
|
|
#include "qtcommon.h"
|
|
|
|
|
#include "extension.h"
|
|
|
|
|
#include "devtools.h"
|
|
|
|
|
|
|
|
|
|
extern const wchar_t* TRANSLATION_ERROR;
|
2020-11-04 01:23:20 +03:00
|
|
|
|
extern Synchronized<std::wstring> translateTo, translateFrom;
|
2020-10-14 03:37:03 +03:00
|
|
|
|
|
2020-11-04 01:23:20 +03:00
|
|
|
|
bool useCache = true, autoStartChrome = false, headlessChrome = true;
|
|
|
|
|
int maxSentenceSize = 500, chromePort = 9222;
|
2020-10-14 03:37:03 +03:00
|
|
|
|
|
|
|
|
|
const char* TRANSLATION_PROVIDER = "DevTools DeepL Translate";
|
2020-11-04 01:23:20 +03:00
|
|
|
|
const wchar_t* ERROR_CHROME = L"Error: Chrome not started";
|
|
|
|
|
const wchar_t* ERROR_START_CHROME = L"Error: failed to start Chrome or to connect to it";
|
2020-10-15 02:32:58 +03:00
|
|
|
|
const wchar_t* ERROR_GOT_TIMEOUT = L"Error: timeout (s)";
|
|
|
|
|
const wchar_t* ERROR_COMMAND_FAIL = L"Error: command failed";
|
|
|
|
|
const wchar_t* ERROR_LANGUAGE = L"Error: target languages do not match";
|
2020-10-15 23:23:41 +03:00
|
|
|
|
const wchar_t* ERROR_NOTE = L"Error: notification";
|
2020-12-09 14:00:57 +03:00
|
|
|
|
const wchar_t* ERROR_EMPTY_ANSWER = L"Error: empty translation";
|
2020-10-15 02:32:58 +03:00
|
|
|
|
|
2020-10-14 03:37:03 +03:00
|
|
|
|
QString URL = "https://www.deepl.com/en/translator";
|
2020-11-04 01:23:20 +03:00
|
|
|
|
QStringList languagesTo
|
2020-10-14 03:37:03 +03:00
|
|
|
|
{
|
|
|
|
|
"Chinese (simplified): zh",
|
|
|
|
|
"Dutch: nl",
|
|
|
|
|
"English: en",
|
|
|
|
|
"French: fr",
|
|
|
|
|
"German: de",
|
|
|
|
|
"Italian: it",
|
|
|
|
|
"Japanese: ja",
|
|
|
|
|
"Polish: pl",
|
|
|
|
|
"Portuguese: pt",
|
|
|
|
|
"Russian: ru",
|
|
|
|
|
"Spanish: es",
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-04 01:23:20 +03:00
|
|
|
|
QStringList languagesFrom
|
|
|
|
|
{
|
|
|
|
|
"Any language: ",
|
|
|
|
|
"Chinese: zh",
|
|
|
|
|
"Dutch: nl",
|
|
|
|
|
"English: en",
|
|
|
|
|
"French: fr",
|
|
|
|
|
"German: de",
|
|
|
|
|
"Italian: it",
|
|
|
|
|
"Japanese: ja",
|
|
|
|
|
"Polish: pl",
|
|
|
|
|
"Portuguese: pt",
|
|
|
|
|
"Russian: ru",
|
|
|
|
|
"Spanish: es",
|
|
|
|
|
};
|
2020-10-14 03:37:03 +03:00
|
|
|
|
|
2020-11-04 20:51:23 +03:00
|
|
|
|
int docFound = -1, targetNodeId = -1, session = -1, pageEnabled = -1, userAgentFlag = -1, backup = -1, sourceLangId = -1, mobileShareId = -1;
|
2020-11-04 01:23:20 +03:00
|
|
|
|
long update = -1, callNumber = 0;
|
|
|
|
|
std::vector<long> callQueue;
|
|
|
|
|
|
|
|
|
|
std::pair<bool, std::wstring> Translate(const std::wstring& text, DevTools* devTools)
|
2020-10-14 03:37:03 +03:00
|
|
|
|
{
|
|
|
|
|
QString qtext = S(text);
|
2020-10-20 02:08:59 +03:00
|
|
|
|
qtext.remove(QString(12288)); // japanese space (no need for translator)
|
2020-12-09 14:00:57 +03:00
|
|
|
|
qtext.replace(QString(12289), ","); // replace the japanese comma with the latin comma for correct translation
|
2020-10-14 03:37:03 +03:00
|
|
|
|
|
2020-10-22 23:15:45 +03:00
|
|
|
|
// Remove quotes
|
2020-11-04 01:23:20 +03:00
|
|
|
|
bool checkQuote = false;
|
2020-10-20 02:08:59 +03:00
|
|
|
|
if ((qtext.front() == QString(12300) && qtext.back() == QString(12301)) // japanese quotation marks
|
|
|
|
|
|| (qtext.front() == "\"" && qtext.back() == "\""))
|
|
|
|
|
{
|
2020-11-04 01:23:20 +03:00
|
|
|
|
checkQuote = true;
|
2020-10-20 02:08:59 +03:00
|
|
|
|
qtext.remove(0, 1);
|
|
|
|
|
qtext.chop(1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 23:15:45 +03:00
|
|
|
|
// Check specific cases (sentence has only one japanese symbol or consists of ellipsis)
|
2020-10-20 02:08:59 +03:00
|
|
|
|
int count = qtext.count(QString(8230)); // ellipsis
|
|
|
|
|
if (count == qtext.length()
|
|
|
|
|
|| (count == (qtext.length() - 1) && qtext.back() == QString(12290))) // japanese end of a sentence
|
|
|
|
|
{
|
|
|
|
|
return { true, text };
|
|
|
|
|
}
|
2020-10-22 23:15:45 +03:00
|
|
|
|
if (count == (qtext.length() - 1))
|
|
|
|
|
{
|
|
|
|
|
qtext.remove(QString(8230));
|
|
|
|
|
qtext += QString(12290) + QString(8230); // add the end symbol for correct translation
|
|
|
|
|
}
|
2020-10-15 23:23:41 +03:00
|
|
|
|
|
2020-10-20 02:08:59 +03:00
|
|
|
|
// Put quotes back
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (checkQuote)
|
2020-10-20 02:08:59 +03:00
|
|
|
|
{
|
|
|
|
|
qtext = "\"" + qtext + "\"";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check status
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (devTools->getStatus() == "Stopped")
|
2020-10-15 02:32:58 +03:00
|
|
|
|
{
|
|
|
|
|
return { false, FormatString(L"%s", ERROR_CHROME) };
|
|
|
|
|
}
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (devTools->getStatus().startsWith("Fail") || devTools->getStatus().startsWith("Unconnected"))
|
2020-10-15 02:32:58 +03:00
|
|
|
|
{
|
|
|
|
|
return { false, FormatString(L"%s", ERROR_START_CHROME) };
|
|
|
|
|
}
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (session != devTools->getSession())
|
2020-10-15 02:32:58 +03:00
|
|
|
|
{
|
2020-11-04 01:23:20 +03:00
|
|
|
|
session = devTools->getSession();
|
|
|
|
|
docFound = -1;
|
2020-10-15 02:32:58 +03:00
|
|
|
|
targetNodeId = -1;
|
2020-11-04 01:23:20 +03:00
|
|
|
|
sourceLangId = -1;
|
2020-11-04 20:51:23 +03:00
|
|
|
|
mobileShareId = -1;
|
2020-11-04 01:23:20 +03:00
|
|
|
|
pageEnabled = -1;
|
|
|
|
|
userAgentFlag = -1;
|
2020-10-20 02:08:59 +03:00
|
|
|
|
update = -1;
|
2020-11-04 01:23:20 +03:00
|
|
|
|
callNumber = 0;
|
2020-10-29 02:08:11 +03:00
|
|
|
|
backup = -1;
|
2020-10-15 02:32:58 +03:00
|
|
|
|
}
|
2020-10-14 03:37:03 +03:00
|
|
|
|
|
2020-10-22 23:15:45 +03:00
|
|
|
|
// Remove tags and reduce the number of ellipsis for correct translation
|
2020-10-20 02:08:59 +03:00
|
|
|
|
qtext.remove(QRegExp("<[^>]*>"));
|
|
|
|
|
qtext.replace(QRegExp("(" + QString(8230) + ")+"), " " + QString(8230));
|
2020-10-14 03:37:03 +03:00
|
|
|
|
|
|
|
|
|
// Enable page feedback
|
2020-10-20 02:08:59 +03:00
|
|
|
|
QJsonObject root;
|
2020-11-04 01:23:20 +03:00
|
|
|
|
int errorCode = 0;
|
|
|
|
|
if (pageEnabled == -1)
|
2020-10-14 03:37:03 +03:00
|
|
|
|
{
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (!devTools->SendRequest("Page.enable", {}, root))
|
|
|
|
|
errorCode = 1;
|
2020-10-22 23:15:45 +03:00
|
|
|
|
else
|
2020-11-04 01:23:20 +03:00
|
|
|
|
pageEnabled = 1;
|
2020-10-14 03:37:03 +03:00
|
|
|
|
}
|
2020-10-18 16:16:06 +03:00
|
|
|
|
|
|
|
|
|
// Change user-agent if in headless mode
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (userAgentFlag == -1 && errorCode == 0)
|
2020-10-18 16:16:06 +03:00
|
|
|
|
{
|
2020-11-04 01:23:20 +03:00
|
|
|
|
QString userAgent = devTools->getUserAgent();
|
|
|
|
|
if (!userAgent.isEmpty())
|
2020-10-18 16:16:06 +03:00
|
|
|
|
{
|
2020-11-04 01:23:20 +03:00
|
|
|
|
userAgent.replace("HeadlessChrome", "Chrome");
|
|
|
|
|
if (!devTools->SendRequest("Network.setUserAgentOverride", { {"userAgent", userAgent} }, root))
|
|
|
|
|
errorCode = 1;
|
2020-10-22 23:15:45 +03:00
|
|
|
|
else
|
2020-11-04 01:23:20 +03:00
|
|
|
|
userAgentFlag = 1;
|
2020-10-18 16:16:06 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 23:15:45 +03:00
|
|
|
|
// Increase queue counter and wait until previous calls are done
|
2020-10-21 00:10:58 +03:00
|
|
|
|
float timer = 0;
|
2020-11-04 01:23:20 +03:00
|
|
|
|
int timerStop = 10;
|
|
|
|
|
long callTag = ++callNumber;
|
|
|
|
|
callQueue.insert(callQueue.begin(), callTag);
|
|
|
|
|
while (errorCode == 0 && callQueue.back() != callTag && timer < 2 * timerStop)
|
2020-10-21 00:10:58 +03:00
|
|
|
|
{
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
|
timer += 0.1;
|
|
|
|
|
}
|
2020-12-09 14:00:57 +03:00
|
|
|
|
if (timer >= 2 * timerStop)
|
2020-11-04 01:23:20 +03:00
|
|
|
|
errorCode = 5;
|
2020-10-22 23:15:45 +03:00
|
|
|
|
|
|
|
|
|
// Set methods to receive
|
2020-11-04 01:23:20 +03:00
|
|
|
|
long navigate = devTools->methodToReceive("Page.navigatedWithinDocument");
|
2020-10-29 02:08:11 +03:00
|
|
|
|
long target;
|
2020-11-04 20:51:23 +03:00
|
|
|
|
if (mobileShareId != -1 && backup == -1)
|
|
|
|
|
target = devTools->methodToReceive("DOM.attributeModified", { { "nodeId" , mobileShareId } , { "value" , "lmt__mobile_share_container lmt--mobile-hidden" } });
|
|
|
|
|
else if (mobileShareId == -1 && backup == -1)
|
2020-11-04 01:23:20 +03:00
|
|
|
|
target = devTools->methodToReceive("DOM.attributeModified", { { "value" , "lmt__mobile_share_container lmt--mobile-hidden" } });
|
2020-10-29 02:08:11 +03:00
|
|
|
|
else
|
2020-11-04 01:23:20 +03:00
|
|
|
|
target = devTools->methodToReceive("DOM.childNodeCountUpdated");
|
2020-10-20 02:08:59 +03:00
|
|
|
|
if (update == -1)
|
2020-11-04 01:23:20 +03:00
|
|
|
|
update = devTools->methodToReceive("DOM.documentUpdated");
|
2020-10-14 03:37:03 +03:00
|
|
|
|
|
2020-10-22 23:15:45 +03:00
|
|
|
|
// Navigate to site and wait until it is loaded
|
2020-11-04 01:23:20 +03:00
|
|
|
|
QString checkFrom = translateFrom.Copy().empty() ? "ja" : S(translateFrom.Copy());
|
|
|
|
|
QString fullUrl = URL + "#" + checkFrom + "/" + S(translateTo.Copy()) + "/" + qtext;
|
|
|
|
|
if (errorCode == 0 && !devTools->SendRequest("Page.navigate", { {"url", fullUrl} }, root))
|
|
|
|
|
errorCode = 1;
|
2020-10-21 00:10:58 +03:00
|
|
|
|
timer = 0;
|
2020-11-04 01:23:20 +03:00
|
|
|
|
while (errorCode == 0 && !devTools->checkMethod(navigate) && timer < timerStop)
|
2020-10-20 02:08:59 +03:00
|
|
|
|
{
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
|
timer += 0.1;
|
|
|
|
|
}
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (timer >= timerStop)
|
|
|
|
|
errorCode = 2;
|
2020-10-14 03:37:03 +03:00
|
|
|
|
|
2020-10-20 02:08:59 +03:00
|
|
|
|
// Check if document is outdated
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (devTools->checkMethod(update))
|
2020-10-20 02:08:59 +03:00
|
|
|
|
{
|
2020-11-04 01:23:20 +03:00
|
|
|
|
docFound = -1;
|
2020-10-20 02:08:59 +03:00
|
|
|
|
targetNodeId = -1;
|
|
|
|
|
update = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get document
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (docFound == -1 && errorCode == 0)
|
2020-10-20 02:08:59 +03:00
|
|
|
|
{
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (!devTools->SendRequest("DOM.getDocument", {}, root))
|
|
|
|
|
errorCode = 1;
|
2020-10-22 23:15:45 +03:00
|
|
|
|
else
|
2020-11-04 01:23:20 +03:00
|
|
|
|
docFound = root.value("result").toObject().value("root").toObject().value("nodeId").toInt();
|
2020-10-20 02:08:59 +03:00
|
|
|
|
}
|
2020-10-14 03:37:03 +03:00
|
|
|
|
|
2020-10-20 02:08:59 +03:00
|
|
|
|
// Get target selector
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (targetNodeId == -1 && errorCode == 0)
|
2020-10-20 02:08:59 +03:00
|
|
|
|
{
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (!devTools->SendRequest("DOM.querySelector", { {"nodeId", docFound}, {"selector", "textarea.lmt__target_textarea"} }, root)
|
2020-10-20 02:08:59 +03:00
|
|
|
|
|| root.value("result").toObject().value("nodeId").toInt() == 0)
|
2020-10-14 03:37:03 +03:00
|
|
|
|
{
|
2020-11-04 01:23:20 +03:00
|
|
|
|
docFound = -1;
|
|
|
|
|
errorCode = 1;
|
2020-10-14 03:37:03 +03:00
|
|
|
|
}
|
2020-10-22 23:15:45 +03:00
|
|
|
|
else
|
|
|
|
|
targetNodeId = root.value("result").toObject().value("nodeId").toInt();
|
2020-10-20 02:08:59 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 01:23:20 +03:00
|
|
|
|
// Get source language selector
|
|
|
|
|
if (sourceLangId == -1 && errorCode == 0)
|
|
|
|
|
{
|
|
|
|
|
if (!devTools->SendRequest("DOM.querySelector", { {"nodeId", docFound}, {"selector", "div.lmt__language_select--source"} }, root)
|
|
|
|
|
|| root.value("result").toObject().value("nodeId").toInt() == 0)
|
|
|
|
|
{
|
|
|
|
|
docFound = -1;
|
|
|
|
|
errorCode = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
sourceLangId = root.value("result").toObject().value("nodeId").toInt();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 20:51:23 +03:00
|
|
|
|
// Get mobile share selector
|
|
|
|
|
if (mobileShareId == -1 && errorCode == 0)
|
|
|
|
|
{
|
|
|
|
|
if (!devTools->SendRequest("DOM.querySelector", { {"nodeId", docFound}, {"selector", "div.lmt__mobile_share_container"} }, root)
|
|
|
|
|
|| root.value("result").toObject().value("nodeId").toInt() == 0)
|
|
|
|
|
{
|
|
|
|
|
docFound = -1;
|
|
|
|
|
errorCode = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
mobileShareId = root.value("result").toObject().value("nodeId").toInt();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 23:15:45 +03:00
|
|
|
|
// Wait for the translation to appear on the web page
|
2020-10-20 02:08:59 +03:00
|
|
|
|
timer = 0;
|
2020-11-04 01:23:20 +03:00
|
|
|
|
while (errorCode == 0 && !devTools->checkMethod(target) && timer < timerStop)
|
2020-10-20 02:08:59 +03:00
|
|
|
|
{
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
|
timer += 0.1;
|
|
|
|
|
}
|
2020-10-21 00:10:58 +03:00
|
|
|
|
|
2020-10-20 02:08:59 +03:00
|
|
|
|
// Catch the translation
|
2020-10-22 23:15:45 +03:00
|
|
|
|
QString OuterHTML;
|
2020-12-09 14:00:57 +03:00
|
|
|
|
if (errorCode == 0)
|
2020-10-22 23:15:45 +03:00
|
|
|
|
{
|
2020-12-09 14:00:57 +03:00
|
|
|
|
if (!devTools->SendRequest("DOM.getOuterHTML", { {"nodeId", targetNodeId + 1} }, root))
|
|
|
|
|
{
|
|
|
|
|
targetNodeId = -1;
|
|
|
|
|
errorCode = 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OuterHTML = root.value("result").toObject().value("outerHTML").toString();
|
|
|
|
|
}
|
2020-10-20 02:08:59 +03:00
|
|
|
|
}
|
2020-12-09 14:00:57 +03:00
|
|
|
|
if (errorCode == 0 && OuterHTML == "<div></div>")
|
2020-10-20 02:08:59 +03:00
|
|
|
|
{
|
|
|
|
|
// Try to catch the notification
|
|
|
|
|
int noteNodeId = -1;
|
2020-12-09 14:00:57 +03:00
|
|
|
|
if (!devTools->SendRequest("DOM.querySelector", { {"nodeId", docFound}, {"selector", "div.lmt__system_notification"} }, root)
|
|
|
|
|
|| root.value("result").toObject().value("nodeId").toInt() == 0)
|
2020-10-14 03:37:03 +03:00
|
|
|
|
{
|
2020-12-09 14:00:57 +03:00
|
|
|
|
if (timer >= timerStop)
|
|
|
|
|
errorCode = 2;
|
|
|
|
|
else
|
|
|
|
|
errorCode = 6;
|
2020-10-20 02:08:59 +03:00
|
|
|
|
}
|
2020-10-22 23:15:45 +03:00
|
|
|
|
else
|
2020-10-20 02:08:59 +03:00
|
|
|
|
{
|
2020-10-22 23:15:45 +03:00
|
|
|
|
noteNodeId = root.value("result").toObject().value("nodeId").toInt();
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (errorCode == 0 && devTools->SendRequest("DOM.getOuterHTML", { {"nodeId", noteNodeId} }, root))
|
2020-10-22 23:15:45 +03:00
|
|
|
|
{
|
|
|
|
|
OuterHTML = root.value("result").toObject().value("outerHTML").toString();
|
|
|
|
|
}
|
2020-11-04 01:23:20 +03:00
|
|
|
|
errorCode = 3;
|
2020-10-14 03:37:03 +03:00
|
|
|
|
}
|
2020-10-20 02:08:59 +03:00
|
|
|
|
}
|
|
|
|
|
OuterHTML.remove(QRegExp("<[^>]*>"));
|
|
|
|
|
OuterHTML = OuterHTML.trimmed();
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (backup == -1 && errorCode == 0 && timer >= timerStop)
|
2020-10-29 02:08:11 +03:00
|
|
|
|
backup = 1;
|
2020-10-20 02:08:59 +03:00
|
|
|
|
|
|
|
|
|
// Check if the translator output language does not match the selected language
|
2020-11-04 01:23:20 +03:00
|
|
|
|
QString targetLang;
|
|
|
|
|
if (errorCode == 0 && devTools->SendRequest("DOM.getAttributes", { {"nodeId", targetNodeId} }, root))
|
2020-10-20 02:08:59 +03:00
|
|
|
|
{
|
2020-10-22 23:15:45 +03:00
|
|
|
|
QJsonArray attributes = root.value("result").toObject().value("attributes").toArray();
|
2020-10-20 02:08:59 +03:00
|
|
|
|
for (size_t i = 0; i < attributes.size(); i++)
|
2020-10-14 03:37:03 +03:00
|
|
|
|
{
|
2020-10-20 02:08:59 +03:00
|
|
|
|
if (attributes[i].toString() == "lang")
|
2020-10-14 03:37:03 +03:00
|
|
|
|
{
|
2020-11-04 01:23:20 +03:00
|
|
|
|
targetLang = attributes[i + 1].toString().mid(0, 2);
|
|
|
|
|
if (targetLang != S(translateTo.Copy()))
|
|
|
|
|
{
|
|
|
|
|
errorCode = 4;
|
|
|
|
|
}
|
2020-12-13 00:56:00 +03:00
|
|
|
|
break;
|
2020-11-04 01:23:20 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check selected source language
|
|
|
|
|
if (errorCode == 0 && devTools->SendRequest("DOM.getAttributes", { {"nodeId", sourceLangId} }, root))
|
|
|
|
|
{
|
|
|
|
|
QJsonArray attributes = root.value("result").toObject().value("attributes").toArray();
|
|
|
|
|
for (size_t i = 0; i < attributes.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
if (attributes[i].toString() == "dl-selected-lang"
|
|
|
|
|
&& attributes[i + 1].toString().mid(0, 2) != S(translateFrom.Copy()))
|
|
|
|
|
{
|
|
|
|
|
QStringList::const_iterator constIter;
|
|
|
|
|
for (constIter = languagesFrom.constBegin(); constIter != languagesFrom.constEnd(); ++constIter)
|
2020-10-14 03:37:03 +03:00
|
|
|
|
{
|
2020-11-04 01:23:20 +03:00
|
|
|
|
if (constIter->contains(": " + S(translateFrom.Copy())))
|
|
|
|
|
break;
|
2020-10-14 03:37:03 +03:00
|
|
|
|
}
|
2020-11-04 01:23:20 +03:00
|
|
|
|
devTools->SendRequest("Runtime.evaluate", { {"expression",
|
|
|
|
|
"document\
|
|
|
|
|
.querySelector('div.lmt__language_select--source')\
|
|
|
|
|
.querySelector('button.lmt__language_select__active')\
|
|
|
|
|
.click();\
|
|
|
|
|
document\
|
|
|
|
|
.evaluate(\"//button[contains(text(), '"
|
|
|
|
|
+ constIter->split(": ")[0] + "')]\", \
|
|
|
|
|
document.querySelector('div.lmt__language_select__menu'),\
|
|
|
|
|
null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)\
|
|
|
|
|
.singleNodeValue\
|
|
|
|
|
.click();"
|
|
|
|
|
} }, root);
|
2020-10-14 03:37:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-22 23:15:45 +03:00
|
|
|
|
|
2020-11-04 01:23:20 +03:00
|
|
|
|
callQueue.pop_back();
|
|
|
|
|
if (errorCode == 0)
|
2020-10-22 23:15:45 +03:00
|
|
|
|
return { true, S(OuterHTML) };
|
2020-11-04 01:23:20 +03:00
|
|
|
|
else if (errorCode == 1)
|
2020-10-22 23:15:45 +03:00
|
|
|
|
return { false, FormatString(L"%s", ERROR_COMMAND_FAIL) };
|
2020-11-04 01:23:20 +03:00
|
|
|
|
else if (errorCode == 2)
|
|
|
|
|
return { false, FormatString(L"%s: %d", ERROR_GOT_TIMEOUT, timerStop) };
|
|
|
|
|
else if (errorCode == 3)
|
2020-10-22 23:15:45 +03:00
|
|
|
|
return { false, FormatString(L"%s: %s", ERROR_NOTE, S(OuterHTML)) };
|
2020-11-04 01:23:20 +03:00
|
|
|
|
else if (errorCode == 4)
|
|
|
|
|
return { false, FormatString(L"%s (%s): %s", ERROR_LANGUAGE, S(targetLang), S(OuterHTML)) };
|
|
|
|
|
else if (errorCode == 5)
|
|
|
|
|
return { false, FormatString(L"%s: %d", ERROR_GOT_TIMEOUT, 2*timerStop) };
|
2020-12-09 14:00:57 +03:00
|
|
|
|
else if (errorCode == 6)
|
|
|
|
|
return { false, FormatString(L"%s", ERROR_EMPTY_ANSWER) };
|
2020-10-22 23:15:45 +03:00
|
|
|
|
else
|
|
|
|
|
return { false, FormatString(L"%s", TRANSLATION_ERROR) };
|
2020-10-15 23:23:41 +03:00
|
|
|
|
}
|