-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontent-script.js
More file actions
24 lines (21 loc) · 813 Bytes
/
content-script.js
File metadata and controls
24 lines (21 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const getActiveElement = function (document) {
document = document || window.document;
// Check if the active element is in the main web or iframe
if (document.body === document.activeElement
|| document.activeElement.tagName == 'IFRAME') {
// Get iframes
const iframes = document.getElementsByTagName('iframe');
for (let i = 0; i < iframes.length; i++) {
// Recall
const focused = getActiveElement(iframes[i].contentWindow.document);
if (focused !== false) {
return focused; // The focused
}
}
} else return document.activeElement;
return false;
};
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
getActiveElement().value = request;
});