From 6958b22e68700ef160fb59cba005b672b6c8aaad Mon Sep 17 00:00:00 2001 From: zeheyler Date: Wed, 4 Nov 2020 20:51:23 +0300 Subject: [PATCH] fix target selector check Fixed target selector check in some cases Changed line endings from CRLF to LF --- extensions/devtoolsdeepltranslate.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/extensions/devtoolsdeepltranslate.cpp b/extensions/devtoolsdeepltranslate.cpp index 3efcf84..f227706 100644 --- a/extensions/devtoolsdeepltranslate.cpp +++ b/extensions/devtoolsdeepltranslate.cpp @@ -48,7 +48,7 @@ QStringList languagesFrom "Spanish: es", }; -int docFound = -1, targetNodeId = -1, session = -1, pageEnabled = -1, userAgentFlag = -1, backup = -1, sourceLangId = -1; +int docFound = -1, targetNodeId = -1, session = -1, pageEnabled = -1, userAgentFlag = -1, backup = -1, sourceLangId = -1, mobileShareId = -1; long update = -1, callNumber = 0; std::vector callQueue; @@ -101,6 +101,7 @@ std::pair Translate(const std::wstring& text, DevTools* devT docFound = -1; targetNodeId = -1; sourceLangId = -1; + mobileShareId = -1; pageEnabled = -1; userAgentFlag = -1; update = -1; @@ -153,7 +154,9 @@ std::pair Translate(const std::wstring& text, DevTools* devT // Set methods to receive long navigate = devTools->methodToReceive("Page.navigatedWithinDocument"); long target; - if (backup == -1) + 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) target = devTools->methodToReceive("DOM.attributeModified", { { "value" , "lmt__mobile_share_container lmt--mobile-hidden" } }); else target = devTools->methodToReceive("DOM.childNodeCountUpdated"); @@ -217,6 +220,19 @@ std::pair Translate(const std::wstring& text, DevTools* devT sourceLangId = root.value("result").toObject().value("nodeId").toInt(); } + // 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(); + } + // Wait for the translation to appear on the web page timer = 0; while (errorCode == 0 && !devTools->checkMethod(target) && timer < timerStop)