diff --git a/README.md b/README.md index aef7ca5..4e61153 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ The extension can be downloaded from here: * From the **Edge Web store** here: https://microsoftedge.microsoft.com/addons/detail/talktochatgpt/bkkdkngklccknmoalpoakglipbibafpn * Manual installation option, detailed further below -After installing the extension, open or reload the ChatGPT page ( https://chat.openai.com/ ) and you should be seeing a 'Start' button on the top right corner of the page. After you click Start, you will be asked for permission to use your Microphone. This is required to enable voice recognition. +After installing the extension, open or reload the ChatGPT page ( https://chatgpt.com/ ) and you should be seeing a 'Start' button on the top right corner of the page. After you click Start, you will be asked for permission to use your Microphone. This is required to enable voice recognition. ![Talk-to-GPT Widget](/images/260-main.png?raw=true "Talk-to-ChatGPT Widget") diff --git a/chrome-extension/content.js b/chrome-extension/content.js index cc63bf4..a1f31fc 100644 --- a/chrome-extension/content.js +++ b/chrome-extension/content.js @@ -3,7 +3,7 @@ // Author : C. NEDELCU // Version : 2.9.0 (17/09/2023) // Git repo : https://github.com/C-Nedelcu/talk-to-chatgpt -// Chat GPT URL : https://chat.openai.com/chat +// Chat GPT URL : https://chatgpt.com // How to use : https://www.youtube.com/watch?v=VXkLQMEs3lA // Credits : C. NEDELCU (code), pixelsoda (GUI), S. James (GUI) @@ -955,28 +955,38 @@ function CN_ToggleButtonClick() { return; } +// Global descriptor caches to avoid repeated definitions +let textareaDescriptorCache = null; +let prototypeDescriptorCache = null; + +// Function to set native value with descriptor caching +function setNativeValue(element, value) { + if (!textareaDescriptorCache || !prototypeDescriptorCache) { + textareaDescriptorCache = Object.getOwnPropertyDescriptor(element, 'value') || {}; + const prototype = Object.getPrototypeOf(element); + prototypeDescriptorCache = Object.getOwnPropertyDescriptor(prototype, 'value') || {}; + } + + const { set: valueSetter } = textareaDescriptorCache; + const { set: prototypeValueSetter } = prototypeDescriptorCache; + + if (prototypeValueSetter && valueSetter !== prototypeValueSetter) { + prototypeValueSetter.call(element, value); + } else if (valueSetter) { + valueSetter.call(element, value); + } else { + throw new Error('The given element does not have a value setter'); + } } - +// Function to set textarea value and dispatch input event function CN_SetTextareaValue(text) { - const textarea = jQuery("#prompt-textarea")[0]; - function setNativeValue(element, value) { - const { set: valueSetter } = Object.getOwnPropertyDescriptor(element, 'value') || {} - const prototype = Object.getPrototypeOf(element) - const { set: prototypeValueSetter } = Object.getOwnPropertyDescriptor(prototype, 'value') || {} - - if (prototypeValueSetter && valueSetter !== prototypeValueSetter) { - prototypeValueSetter.call(element, value) - } else if (valueSetter) { - valueSetter.call(element, value) - } else { - throw new Error('The given element does not have a value setter') - } - } - setNativeValue(textarea, text) - textarea.dispatchEvent(new Event('input', { bubbles: true })) + const textarea = jQuery("#prompt-textarea")[0]; + setNativeValue(textarea, text); + textarea.dispatchEvent(new Event('input', { bubbles: true })); } + function CN_PlaySound(audioData, onEnded, transcript) { //console.log("PlaySound - "+onEnded); chrome.runtime.sendMessage({ diff --git a/chrome-extension/manifest.json b/chrome-extension/manifest.json index 1e9edc1..859d9a1 100644 --- a/chrome-extension/manifest.json +++ b/chrome-extension/manifest.json @@ -14,7 +14,7 @@ "content_scripts":[ { "matches":[ - "https://chat.openai.com/*" + "https://chatgpt.com/*" ], "js": ["jquery.min.js", "fontawesome.min.js", "content.js"] } diff --git a/chrome-extension/popup.html b/chrome-extension/popup.html index c149700..b4397b5 100644 --- a/chrome-extension/popup.html +++ b/chrome-extension/popup.html @@ -8,7 +8,7 @@