-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathChatGPT出错时自动刷新页面重新提问.js
59 lines (59 loc) · 2.29 KB
/
ChatGPT出错时自动刷新页面重新提问.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// ==UserScript==
// @name ChatGPT 出错时自动刷新页面重新提问
// @namespace http://tampermonkey.net/
// @version 0.1
// @description ChatGPT 出错时自动刷新页面重新提问
// @author Hao Liu
// @match https://chat.openai.com/c/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
// ChatGPT 出错时自动刷新页面重新提问
(function() {
'use strict';
let key = "ChatGPT_question2"
window.onload = ()=>{
let value = GM_getValue(key, '')
console.log(value)
if(value){
const id = setInterval(() => {
// 等待出现对话
const mask = document.getElementsByClassName("rounded-sm")
if(!mask?.length) return
// 等待出现输入框或“重新提问”按钮
const input = document.querySelector('textarea')
const reopen = document.querySelector('.btn.relative.btn-primary.m-auto')
if(!reopen && !input ) return
if(reopen && reopen.textContent.indexOf('Regenerate') > -1) {
reopen.click()
} else if (input) {
input.value = value
const btn = input.parentElement.querySelector('button')
btn.disabled = false
btn.click()
} else return
clearInterval(id)
GM_setValue(key, '')
}, 1000);
}
const id = setInterval(() => {
// 灰色 div 容器(ChatGPT 回复)
let gray = document.querySelectorAll('div.bg-gray-50')
let last = gray[gray.length-1]
// 错误
let err = last?.querySelector('.border-red-500')
if(err) {
// 最后的提问
let question = last.previousSibling.querySelector('.flex-grow.gap-3').textContent
if(question.length > 1000){
console.error('问题过长')
question = ''
}
GM_setValue(key, question)
clearInterval(id)
location.reload()
}
}, 500);
}
})();