From b29dcfd34f28095fd5cb70cf0a3a1982ac92d78d Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Sat, 2 May 2020 22:49:31 +0800 Subject: [PATCH] Refactory code. --- core/js/get_focus_text.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/js/get_focus_text.js b/core/js/get_focus_text.js index 7e78197..c9064d8 100644 --- a/core/js/get_focus_text.js +++ b/core/js/get_focus_text.js @@ -1,17 +1,20 @@ (function() { const activeElement = document.activeElement; var inputs = ["input", "select", "textarea"]; + var pageUrl = window.location.href; + var tagName = activeElement.tagName.toLowerCase(); - if (window.location.href === "https://mail.qq.com/" && activeElement) { + if (pageUrl === "https://mail.qq.com/" && activeElement) { // QQ mail have some security mechanism that we can't fetch value of activeElement. // So we just return empty string make is_focus method works well in browser.py return ""; - } else if (activeElement && inputs.indexOf(activeElement.tagName.toLowerCase()) !== -1) { + } else if (activeElement && inputs.indexOf(tagName) !== -1) { return activeElement.value; } else { - if (window.location.href.startsWith("https://web.telegram.org/") && activeElement.hasAttribute("placeholder")) { + if (pageUrl.startsWith("https://web.telegram.org/") && activeElement.hasAttribute("placeholder")) { return activeElement.textContent; - } else if ((window.location.href.startsWith("https://console.cloud.google.com/") || window.location.href.startsWith("https://ssh.cloud.google.com/")) && activeElement.tagName.toLowerCase() == "iframe") { + } else if ((pageUrl.startsWith("https://console.cloud.google.com/") || pageUrl.startsWith("https://ssh.cloud.google.com/")) && tagName == "iframe") { + // Make user can type text in Terminal of Google Cloud. return ""; } else { return undefined;