Skip to content

Instantly share code, notes, and snippets.

@mofelee
Last active November 25, 2023 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mofelee/08f8de0772d3b54d7a6bd9eb84fe13bd to your computer and use it in GitHub Desktop.
Save mofelee/08f8de0772d3b54d7a6bd9eb84fe13bd to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name ChatGPT Helper
// @namespace https://mofe.me/
// @version 0.6
// @description ChatGPT Helper
// @author Mofe Lee
// @match https://chat.openai.com/*
// @run-at document-idle
// @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
// @grant none
// ==/UserScript==
(async ()=> {
const hash = location.hash;
const delay = (ms) => new Promise(resolve=>setTimeout(resolve, ms));
const setInputText = (ele, text)=>{
ele.value = text;
let e = new Event('input', {
'bubbles': true,
'cancelable': true
});
ele.dispatchEvent(e);
}
async function waitForList(){
while(!document.querySelector('#__next ol > li')){
console.log('wait')
await delay(250);
}
}
if(!hash){
return
}
await Promise.all([delay(1500), waitForList()]);
//location.hash = '';
while(!document.querySelector('#prompt-textarea')){
await delay(250)
}
console.log('get prompt');
while(!document.querySelector('#prompt-textarea + div + button')){
await delay(250)
}
console.log('get button');
const prompt = document.querySelector('#prompt-textarea');
const button = document.querySelector('#prompt-textarea + div + button');
let text = decodeURIComponent(hash.replace(/^#/, ''));
if (text.includes('%')) { // Raycast encode text twice
text = decodeURIComponent(text);
}
while(!prompt.value){
console.log('set value');
setInputText(prompt, text);
await delay(500);
}
while(button.disabled){
console.log('wait button');
setInputText(prompt, '');
await delay(300);
setInputText(prompt, text);
await delay(300);
}
while(document.querySelector('#prompt-textarea + div + button')){
/**
if(!prompt.value){
console.log('set value again');
setInputText(prompt, text);
await delay(250);
continue;
}
while(button.disabled){
console.log('wait button')
//button.disabled = false
await delay(250);
}
console.log('try to click button')
if(prompt.value && !button.disabled){
console.log('clicked button');
button.disabled = false;
button.click();
}**/
document.querySelector('#prompt-textarea + div + button').click()
await delay(500);
}
setInputText(prompt, '');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment