Fix for the Javascript code in TamperMonkey
OzAmoyal opened this issue · 1 comments
Hello and thank you for this wonderful extension. When I tried to use it, it did not work with the current script, so I made three minor changes that made it work.
First, I changed the '// @match https://chat.openai.com/chat?PTquery=*' line because the URL opens without the "/chat/" at the end and the browser extension did not recognize it, as shown here:
Second, I added a 500ms wait to the setTimeout Method because without it, the chat would not respond to me and would continue loading, as shown in the image below:
as I said the 500ms wait did fix it but I did not try other variants.
The final change I made was to enable the submit button, which was disabled by default until you typed something into the textbox. As a result, the form with the disabled button would not be submitted.
I've included the updated script below; please test it and let me know if it works for you.
// ==UserScript==
// @name PowerToys Run ChatGPT Helper
// @version 0.1
// @description https://github.com/ferraridavide/ChatGPTPowerToys
// @author Davide Ferrari
// @match https://chat.openai.com/?PTquery=*
// @icon https://raw.githubusercontent.com/ferraridavide/ChatGPTPowerToys/master/src/PowerToys.ChatGPT.BrowserExtension/icons/icon128.png
// @grant none
// ==/UserScript==
// ==UserScript==
// @name PowerToys Run ChatGPT Helper
// @version 0.1
// @description https://github.com/ferraridavide/ChatGPTPowerToys
// @author Davide Ferrari
// @match https://chat.openai.com/?PTquery=*
// @icon https://raw.githubusercontent.com/ferraridavide/ChatGPTPowerToys/master/src/PowerToys.ChatGPT.BrowserExtension/icons/icon128.png
// @grant none
// ==/UserScript==
(function() {
'use strict';
console.log("PowerToys Run ChatGPT Helper script loaded");
const searchParams = new URLSearchParams(window.location.search);
const prompt = searchParams.get("PTquery");
if (prompt) {
const textArea = document.querySelector("form textarea");
const submitButton = document.querySelector("form button");
if (!textArea || !submitButton) {
console.error("Cannot find required elements");
}
textArea.value = prompt;
setTimeout(() => {
textArea.value = prompt;
submitButton.disabled = false;
submitButton.click();
}, 500);
}
})();
Thank you for this! the change in the url from https://chat.openai.com/chat to https://chat.openai.com/ happened just recently, and the issue with the prompt firing too early was already brought up in issue #3
I will update the README.md soon and hopefully the code as well