-
-
Save mofelee/08f8de0772d3b54d7a6bd9eb84fe13bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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