@@ -12,21 +12,6 @@ chrome.storage.sync.get(["num_web_results", "web_access", "region"], (data) => {
12
12
} ) ;
13
13
14
14
15
- function setTitleAndDescription ( ) {
16
- const h1_title = document . evaluate ( "//h1[text()='ChatGPT']" , document , null , XPathResult . FIRST_ORDERED_NODE_TYPE , null ) . singleNodeValue ;
17
- if ( ! h1_title ) {
18
- return ;
19
- }
20
-
21
- h1_title . textContent = "WebChatGPT" ;
22
-
23
- const div = document . createElement ( "div" ) ;
24
- div . classList . add ( "w-full" , "bg-gray-50" , "dark:bg-white/5" , "p-6" , "rounded-md" , "mb-10" , "border" ) ;
25
- div . textContent = "With WebChatGPT you can augment your prompts with relevant web search results for better and up-to-date answers." ;
26
- h1_title . parentNode . insertBefore ( div , h1_title . nextSibling ) ;
27
-
28
- }
29
-
30
15
function showErrorMessage ( e ) {
31
16
console . info ( "WebChatGPT error --> API error: " , e ) ;
32
17
var errorDiv = document . createElement ( "div" ) ;
@@ -91,13 +76,31 @@ function onSubmit(event) {
91
76
}
92
77
}
93
78
79
+ function updateTitleAndDescription ( ) {
80
+ const h1_title = document . evaluate ( "//h1[text()='ChatGPT']" , document , null , XPathResult . FIRST_ORDERED_NODE_TYPE , null ) . singleNodeValue ;
81
+ if ( ! h1_title ) {
82
+ return ;
83
+ }
84
+
85
+ h1_title . textContent = "WebChatGPT" ;
86
+
87
+ const div = document . createElement ( "div" ) ;
88
+ div . classList . add ( "w-full" , "bg-gray-50" , "dark:bg-white/5" , "p-6" , "rounded-md" , "mb-10" , "border" ) ;
89
+ div . textContent = "With WebChatGPT you can augment your prompts with relevant web search results for better and up-to-date answers." ;
90
+ h1_title . parentNode . insertBefore ( div , h1_title . nextSibling ) ;
91
+
92
+ }
93
+
94
94
function updateUI ( ) {
95
95
96
96
if ( document . querySelector ( ".web-chatgpt-toolbar" ) ) {
97
97
return ;
98
98
}
99
99
100
100
textarea = document . querySelector ( "textarea" ) ;
101
+ if ( ! textarea ) {
102
+ return ;
103
+ }
101
104
var textareaWrapper = textarea . parentNode ;
102
105
103
106
var btnSubmit = textareaWrapper . querySelector ( "button" ) ;
@@ -223,20 +226,19 @@ function updateUI() {
223
226
lastElement . appendChild ( footerDiv ) ;
224
227
}
225
228
226
- const titleEl = document . querySelector ( 'title ' ) ;
229
+ const rootEl = document . querySelector ( 'div[id="__next"] ' ) ;
227
230
228
- window . onload = function ( ) {
231
+ window . onload = ( ) => {
232
+
233
+ updateTitleAndDescription ( ) ;
234
+ updateUI ( ) ;
229
235
230
- const observer = new MutationObserver ( ( ) => {
236
+ new MutationObserver ( ( ) => {
231
237
try {
232
- setTitleAndDescription ( ) ;
238
+ updateTitleAndDescription ( ) ;
233
239
updateUI ( ) ;
234
240
} catch ( e ) {
235
241
console . info ( "WebChatGPT error --> Could not update UI:\n" , e . stack ) ;
236
242
}
237
- } ) ;
238
-
239
- observer . observe ( titleEl , {
240
- childList : true
241
- } ) ;
243
+ } ) . observe ( rootEl , { childList : true } ) ;
242
244
} ;
0 commit comments