Skip to content

Commit 704b0b6

Browse files
committed
~fix UI updating not working in some cases
1 parent e413418 commit 704b0b6

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
3-
"name": "Web ChatGPT",
4-
"version": "1.1.0",
3+
"name": "WebChatGPT",
4+
"version": "1.1.1",
55
"description": "Augment your ChatGPT prompts with relevant results from the web.",
66
"icons": {
77
"16": "icons/icon16.png",

manifest.v2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
3-
"name": "Web ChatGPT",
4-
"version": "1.1.0",
3+
"name": "WebChatGPT",
4+
"version": "1.1.1",
55
"description": "Augment your ChatGPT prompts with relevant results from the web.",
66
"icons": {
77
"16": "icons/icon16.png",

script.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,6 @@ chrome.storage.sync.get(["num_web_results", "web_access", "region"], (data) => {
1212
});
1313

1414

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-
3015
function showErrorMessage(e) {
3116
console.info("WebChatGPT error --> API error: ", e);
3217
var errorDiv = document.createElement("div");
@@ -91,13 +76,31 @@ function onSubmit(event) {
9176
}
9277
}
9378

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+
9494
function updateUI() {
9595

9696
if (document.querySelector(".web-chatgpt-toolbar")) {
9797
return;
9898
}
9999

100100
textarea = document.querySelector("textarea");
101+
if (!textarea) {
102+
return;
103+
}
101104
var textareaWrapper = textarea.parentNode;
102105

103106
var btnSubmit = textareaWrapper.querySelector("button");
@@ -223,20 +226,19 @@ function updateUI() {
223226
lastElement.appendChild(footerDiv);
224227
}
225228

226-
const titleEl = document.querySelector('title');
229+
const rootEl = document.querySelector('div[id="__next"]');
227230

228-
window.onload = function() {
231+
window.onload = () => {
232+
233+
updateTitleAndDescription();
234+
updateUI();
229235

230-
const observer = new MutationObserver(() => {
236+
new MutationObserver(() => {
231237
try {
232-
setTitleAndDescription();
238+
updateTitleAndDescription();
233239
updateUI();
234240
} catch (e) {
235241
console.info("WebChatGPT error --> Could not update UI:\n", e.stack);
236242
}
237-
});
238-
239-
observer.observe(titleEl, {
240-
childList: true
241-
});
243+
}).observe(rootEl, { childList: true });
242244
};

0 commit comments

Comments
 (0)