-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent.js
30 lines (29 loc) · 1.12 KB
/
content.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
// window.addEventListener('message', function (event) {
// console.log(event);
// // if (event.data && event.data.extensionMessage) {
// // alert(event.data.extensionMessage);
// // }
// });
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
console.log(request.en);
if (location.href.startsWith("https://bard.google.com")) {
var searchInput = document.getElementsByTagName('textarea')[0];
} else {
var searchInput = document.getElementsByTagName("textarea")[0];
}
if (request.functiontoInvoke == 'translateThenSearch') {
if (location.href.startsWith("https://bard.google.com")) {
searchInput.value = request.en;
searchInput.dispatchEvent(new Event('input'))
document.querySelector(`[mattooltip="Submit"]`).click();
} else {
searchInput.value = request.en;
searchInput.dispatchEvent(new Event('input'))
document.querySelector(`[role="search"]`).submit();
}
} else if (request.functiontoInvoke == 'getSearchInputValue') {
sendResponse({"searchInputValue" : searchInput.value});
}
}
);