-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
35 lines (31 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
31
32
33
34
35
// ChatGPT rejects messages before the page hydrates -- it gives an auth error
// Waiting for the big "ChatGPT" on the background + 300ms seems like enough time
function main() {
const params = new URLSearchParams(window.location.search);
const query = params.get('q')
if (query) {
let intervalId = setInterval(() => {
let headers = [...document.querySelectorAll('h1')]
if (headers && headers.some(header => header.textContent.includes('ChatGPT'))) {
setTimeout(() => { applyQuery(query) }, 300)
clearInterval(intervalId);
}
}, 50);
}
}
function applyQuery(query) {
let promptTextarea = document.querySelector('#prompt-textarea');
let submitButton = promptTextarea.parentElement.querySelector('button');
promptTextarea.focus();
promptTextarea.value = query;
promptTextarea.dispatchEvent(new Event('input', {
'bubbles': true,
'cancelable': true
}));
promptTextarea.dispatchEvent(new Event('change', {
'bubbles': true,
'cancelable': true
}));
submitButton.click();
}
main()