-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbackground.js
34 lines (32 loc) · 1.36 KB
/
background.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
async function askChatGPT(query) {
const observer = new MutationObserver(function (mutations, mutationInstance) {
const someDiv = document.getElementsByTagName("h1")[0]
if (someDiv) {
document.getElementsByTagName("textarea")[0].textContent = query;
submit = document.getElementsByClassName("absolute p-1 rounded-md text-gray-500 bottom-1.5 md:bottom-2.5 hover:bg-gray-100 enabled:dark:hover:text-gray-400 dark:hover:bg-gray-900 disabled:hover:bg-transparent dark:disabled:hover:bg-transparent right-1 md:right-2 disabled:opacity-40")[0]
submit.disabled = false
submit.click()
mutationInstance.disconnect();
}
});
observer.observe(document, {
childList: true,
subtree: true
});
}
chrome.omnibox.onInputEntered.addListener(async function(text) {
var url = 'https://chat.openai.com/';
chrome.tabs.update({url: url}, function() {
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.status === 'complete') {
chrome.scripting
.executeScript({
target : {tabId : tabId},
func : askChatGPT,
args : [ text ],
})
.then(() => console.log("injected a function"));
}
});
});
});