-
Notifications
You must be signed in to change notification settings - Fork 230
/
Copy pathget_focus_text.js
34 lines (33 loc) · 1.49 KB
/
get_focus_text.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(function() {
const activeElement = document.activeElement;
var inputs = ["input", "select", "textarea"];
var inputTypes = ["text", "textarea", "email", "password", "tel", "search"];
var pageUrl = window.location.href;
var tagName = activeElement.tagName.toLowerCase();
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 (pageUrl === "https://mail.163.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(tagName) !== -1 &&
inputTypes.indexOf(activeElement.type) !== -1
) {
return activeElement.value;
} else if (activeElement.isContentEditable) {
// For the Rich Text Editor
return activeElement.textContent;
} else {
if (pageUrl.startsWith("https://web.telegram.org/") && activeElement.hasAttribute("placeholder")) {
return activeElement.textContent;
} 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;
}
}
})();