diff --git a/extensions/devtools.cpp b/extensions/devtools.cpp index 8c4f128..1b5f1b4 100644 --- a/extensions/devtools.cpp +++ b/extensions/devtools.cpp @@ -7,6 +7,8 @@ DevTools::DevTools(QObject* parent) : status("Stopped"), session(0) { + connect(&webSocket, &QWebSocket::stateChanged, this, &DevTools::stateChanged); + connect(&webSocket, &QWebSocket::textMessageReceived, this, &DevTools::onTextMessageReceived); } void DevTools::startDevTools(QString path, bool headless, int port) @@ -29,8 +31,6 @@ void DevTools::startDevTools(QString path, bool headless, int port) { useragent = doc.object().value("User-Agent").toString(); } - connect(&webSocket, &QWebSocket::stateChanged, this, &DevTools::stateChanged); - connect(&webSocket, &QWebSocket::textMessageReceived, this, &DevTools::onTextMessageReceived); webSocket.open(webSocketDebuggerUrl); session += 1; return; diff --git a/extensions/devtoolsdeepltranslate.cpp b/extensions/devtoolsdeepltranslate.cpp index 7f3a67d..7b20d29 100644 --- a/extensions/devtoolsdeepltranslate.cpp +++ b/extensions/devtoolsdeepltranslate.cpp @@ -32,7 +32,7 @@ QStringList languages "Spanish: es", }; -int docfound = -1, targetNodeId = -1, session = -1, pageenabled = -1, useragentflag = -1; +int docfound = -1, targetNodeId = -1, session = -1, pageenabled = -1, useragentflag = -1, backup = -1; long update = -1, callnumber = 0; std::vector callqueue; @@ -88,6 +88,7 @@ std::pair Translate(const std::wstring& text, DevTools* devt useragentflag = -1; update = -1; callnumber = 0; + backup = -1; } // Remove tags and reduce the number of ellipsis for correct translation @@ -134,7 +135,11 @@ std::pair Translate(const std::wstring& text, DevTools* devt // Set methods to receive long navigate = devtools->methodToReceive("Page.navigatedWithinDocument"); - long target = devtools->methodToReceive("DOM.attributeModified", { { "value" , "lmt__mobile_share_container" } }); + long target; + if (backup == -1) + target = devtools->methodToReceive("DOM.attributeModified", { { "value" , "lmt__mobile_share_container lmt--mobile-hidden" } }); + else + target = devtools->methodToReceive("DOM.childNodeCountUpdated"); if (update == -1) update = devtools->methodToReceive("DOM.documentUpdated"); @@ -204,8 +209,8 @@ std::pair Translate(const std::wstring& text, DevTools* devt { // Try to catch the notification int noteNodeId = -1; - if (errorcode == 0 && !devtools->SendRequest("DOM.querySelector", { {"nodeId", docfound}, {"selector", "div.lmt__system_notification"} }, root) - || root.value("result").toObject().value("nodeId").toInt() == 0) + if (errorcode == 0 && (!devtools->SendRequest("DOM.querySelector", { {"nodeId", docfound}, {"selector", "div.lmt__system_notification"} }, root) + || root.value("result").toObject().value("nodeId").toInt() == 0) && timer >= timer_stop) { errorcode = 2; } @@ -221,6 +226,8 @@ std::pair Translate(const std::wstring& text, DevTools* devt } OuterHTML.remove(QRegExp("<[^>]*>")); OuterHTML = OuterHTML.trimmed(); + if (backup == -1 && errorcode == 0 && timer >= timer_stop) + backup = 1; // Check if the translator output language does not match the selected language QString targetlang;