版本: 1.7.1已启动,部分需要魔法。当前线路: ${localStorage.getItem("GPTMODE") ? localStorage.getItem("GPTMODE") : "Default"}
`
resolve(divE)
})
}
async function pivElemAddEventAndValue(append_case) {
var search_content
try {
if (append_case === 7) {
search_content = document.querySelector("#search_form input").value
}
if (append_case === 5) {
search_content = document.getElementById("search-input").value
}
if (append_case === 4) {
search_content = document.getElementById("keyword").value
}
if (append_case === 3) {
search_content = document.querySelectorAll("input")[0].value
}
if (append_case === 2) {
search_content = document.getElementById('kw').value
}
if (append_case === 1) {
try {
search_content = document.querySelector(
"#tsf > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input:nth-child(3)"
).value
} catch (e) {
search_content = document.querySelector("textarea").value
}
}
if (append_case === 0) {
search_content = document.getElementsByClassName('b_searchbox')[0].value
if (!search_content) {
search_content = document.querySelector("textarea[class='b_searchbox']").value;
}
}
} catch (e) {
console.log(e)
}
document.getElementById("gptInput").value = search_content
document.getElementById('button_GPT').addEventListener('click', () => {
your_qus = document.getElementById("gptInput").value
do_it()
})
document.getElementById('updatePubkey').addEventListener('click', () => {
document.getElementById("gptAnswer").innerText = "正在更新,请稍后..."
setPubkey()
})
document.getElementById('modeSelect').addEventListener('change', () => {
const selectEl = document.getElementById('modeSelect');
const selectedValue = selectEl.options[selectEl.selectedIndex].value;
localStorage.setItem('GPTMODE', selectedValue);
if (selectedValue === 'COOLAI') {
initSocket();
}
document.getElementById('gptAnswer').innerHTML = `切换成功,当前模式:${selectedValue}模式`;
});
}
async function appendBox(append_case) {
return new Promise((resolve, reject) => {
creatBox().then((divE) => {
switch (append_case) {
case 0: //bing
if (divE) {
document.getElementById('b_context').prepend(divE)
}
break;
case 1: //google
if (document.getElementsByClassName('TQc1id ')[0]) {
document.getElementsByClassName('TQc1id ')[0].prepend(divE);
} else {
document.getElementById("rcnt").appendChild(divE);
}
break;
case 2: //baidu
if (document.getElementById('content_right')) {
document.getElementById('content_right').prepend(divE)
}
break;
case 3: //yandex
if (document.getElementById('search-result-aside')) {
document.getElementById('search-result-aside').prepend(divE)
}
break;
case 4: //360
if (document.getElementById('side')) {
document.getElementById('side').prepend(divE)
}
break;
case 5: //fsoufsou
let frow = document.querySelectorAll(".flex-row")[2]
if (frow.children.length == 2) {
frow.children.item(1).prepend(divE)
} else {
frow.innerHTML = frow.innerHTML +
`
`
}
break;
case 6: //手机百度
if (document.getElementById('page-bd')) {
document.getElementById('page-bd').prepend(divE)
//调整css
try {
document.querySelector("#gptDiv").style.setProperty("width",
"100%")
document.querySelector("#gptInput").setAttribute("class",
"se-input adjust-input")
} catch (e) {
//TODO handle the exception
}
setTimeout(() => {
document.getElementById("button_GPT").click(); //自动点击
}, 1500)
}
break;
case 7: //duckduckgo
if (document.querySelector('.results--sidebar div')) {
document.querySelector('.results--sidebar div').prepend(divE)
}
break;
default:
if (divE) {
console.log(`啥情况${divE}`)
}
}
}).catch((err) => {
throw new Error(err)
})
resolve("finished")
})
}
//焦点函数
function isBlur() {
var myInput = document.getElementById('gptInput');
if (myInput == document.activeElement) {
return 1
} else {
return 0
}
}
function keyEvent() {
document.onkeydown = function (e) {
var keyNum = window.event ? e.keyCode : e.which;
if (13 == keyNum) {
if (isBlur()) {
document.getElementById('button_GPT').click()
} else {
console.log("失焦不执行")
}
}
}
}
function addBothStyle() {
GM_addStyle(`
#dot{
height: 4px;
width: 4px;
display: inline-block;
border-radius: 2px;
animation: dotting 2.4s infinite step-start;
}
@keyframes dotting {
25%{
box-shadow: 4px 0 0 #71777D;
}
50%{
box-shadow: 4px 0 0 #71777D ,14px 0 0 #71777D;
}
75%{
box-shadow: 4px 0 0 #71777D ,14px 0 0 #71777D, 24px 0 0 #71777D;
}
}
pre{
overflow-x: scroll;
overflow-y: hidden;
background: #fffaec;
border-radius: 4px;
padding: 14px 3px;
}
pre::-webkit-scrollbar {
}
`)
}
function log(a) {
console.log(a)
}
function Uint8ArrayToString(fileData) {
var dataString = "";
for (var i = 0; i < fileData.length; i++) {
dataString += String.fromCharCode(fileData[i]);
}
return dataString
}
function decodeUnicode(str) {
str = str.replace(/\\/g, "%");
//转换中文
str = unescape(str);
//将其他受影响的转换回原来
str = str.replace(/%/g, "\\");
//对网址的链接进行处理
str = str.replace(/\\/g, "");
return str;
}
function mdConverter(rawData) {
var converter = new showdown.Converter(); //增加拓展table
converter.setOption('tables',
true); //启用表格选项。从showdown 1.2.0版开始,表支持已作为可选功能移入核心拓展,showdown.table.min.js扩展已被弃用
return converter.makeHtml(rawData);
}
//实时监控百度,360按钮消失
setInterval(() => {
//百度
if (window.location.href.indexOf("https:\/\/www.baidu.com\/s") > -1 && !isMobile()) {
if (!document.getElementById("gptDiv") && document.getElementById("mybtn")) {
document.getElementById("mybtn").click()
}
if (!document.getElementById("gptDiv") && !document.getElementById("mybtn")) {
addChatBtn();
document.getElementById("mybtn").click()
}
}
//360 注意请如果你在360相关浏览器上使用插件。360搜索将不会生效,因为已被浏览器禁用在so.com网址上使用
if (window.location.href.indexOf("so.com\/s") > -1 && !document.getElementById("gptDiv")) {
GM_add_box_style(1)
addBothStyle()
keyEvent()
appendBox(4).then((res) => {
pivElemAddEventAndValue(4)
})
}
}, 2000)
function generateRandomString(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
var parentID_68686;
function LTD68686() {
let ops = {};
if (parentID_68686) {
ops = {parentMessageId: parentID_68686};
}
console.log(ops)
let finalResult = [];
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://chat.68686.ltd/api/chat-process",
headers: {
"Content-Type": "application/json",
"Referer": "https://chat.68686.ltd/",
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
prompt: your_qus,
options: ops
}),
onloadstart: (stream) => {
let result = "";
const reader = stream.response.getReader();
// console.log(reader.read)
let charsReceived = 0;
reader.read().then(function processText({done, value}) {
if (done) {
highlightCodeStr()
return;
}
charsReceived += value.length;
const chunk = value;
result += chunk;
try {
// console.log(normalArray)
let byteArray = new Uint8Array(chunk);
let decoder = new TextDecoder('utf-8');
let nowResult = JSON.parse(decoder.decode(byteArray))
if (nowResult.text) {
console.log(nowResult)
finalResult = nowResult.text
showAnserAndHighlightCodeStr(finalResult)
}
if (nowResult.id) {
parentID_68686 = nowResult.id;
}
} catch (e) {
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
}
})
}
var messageChain2 = [];//AILS
var messageChain7 = [];//OHTOAI
var messageChain4 = [];//ESO
var messageChain8 = [];//SUPREMES
var messageChain9 = [];//bnu120
var messageChain10 = [];//ftcl
var messageChain3 = [];//LETSEARCH
var messageChain1 = [
{
role: "system",
content: "请以markdown的形式返回答案"
}
];//default AIGCFUN
function addMessageChain(messageChain, element) {
if (messageChain.length >= 6) {
messageChain.shift();
}
messageChain.push(element);
console.log(messageChain)
}
function AILS() {
let now = Date.now();
const pk = `Na3dx_(?qx32l}ep?#:8:mo44;7W\\2W.:nxm:${your_qus.length}`;//查看js的generateSignature函数中的key
let Baseurl = "https://ai.ls/"
generateSignatureWithPkey({
t: now,
m: your_qus || "",
pkey: pk
}).then(sign => {
addMessageChain(messageChain2, {role: "user", content: your_qus})//连续话
console.log(sign)
GM_xmlhttpRequest({
method: "POST",
url: Baseurl + "api/generate",
headers: {
"Content-Type": "application/json",
// "Authorization": "Bearer null",
"Referer": Baseurl,
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
messages: messageChain2,
time: now,
pass: null,
sign: sign,
key: ""
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
let finalResult = result.join("")
try {
console.log(finalResult)
addMessageChain(messageChain2, {
role: "assistant",
content: finalResult
})
showAnserAndHighlightCodeStr(finalResult)
} catch (e) {
console.log(e)
}
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
result.push(d)
showAnserAndHighlightCodeStr(result.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onprogress: function (msg) {
//console.log(msg)
},
onerror: function (err) {
console.log(err)
},
ontimeout: function (err) {
console.log(err)
}
});
});
}
function LERSEARCH() {
let baseURL = "https://chatgpt.letsearches.com/";
addMessageChain(messageChain3, {role: "user", content: your_qus})//连续话
GM_xmlhttpRequest({
method: "POST",
url: baseURL + "api/chat-stream",
headers: {
"Content-Type": "application/json",
"access-code": "",
"path": "v1/chat/completions",
"Referer": baseURL
},
data: JSON.stringify({
messages: messageChain3,
stream: true,
model: "gpt-3.5-turbo",
temperature: 1,
max_tokens: 2000,
presence_penalty: 0
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
let finalResult = result.join("")
try {
console.log(finalResult)
addMessageChain(messageChain3, {
role: "assistant",
content: finalResult
})
showAnserAndHighlightCodeStr(finalResult)
} catch (e) {
console.log(e)
}
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
result.push(d)
showAnserAndHighlightCodeStr(result.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onprogress: function (msg) {
//console.log(msg)
},
onerror: function (err) {
console.log(err)
},
ontimeout: function (err) {
console.log(err)
}
});
}
var userId_wgk = "#/chat/" + Date.now();
function WGK() {
console.log(userId_wgk)
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://chat2.wuguokai.cn/api/chat-process",
headers: {
"Content-Type": "application/json",
// "Authorization": "Bearer null",
"Referer": "https://chat.wuguokai.cn/",
//"Host":"www.aiai.zone",
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
prompt: your_qus,
userId: userId_wgk,
options: {}
}),
onloadstart: (stream) => {
let finalResult = []
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
showAnserAndHighlightCodeStr(finalResult.join(""))
return;
}
try {
// console.log(normalArray)
let byteArray = new Uint8Array(value);
let decoder = new TextDecoder('utf-8');
let nowResult = decoder.decode(byteArray)
finalResult.push(nowResult)
showAnserAndHighlightCodeStr(finalResult.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
showAnserAndHighlightCodeStr("erro:", err)
}
})
}
var userId_yqcloud = "#/chat/" + Date.now();
function YQCLOUD() {
console.log(userId_yqcloud)
abortXml = GM_xmlhttpRequest({
method: "POST",
//url: "https://cbjtestapi.binjie.site:7777/api/generateStream",
url: "https://api.aichatos.cloud/api/generateStream",
headers: {
"Content-Type": "application/json",
"Referer": "https://chat6.aichatos.com/",
"origin": "https://chat6.aichatos.com",
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
prompt: your_qus,
apikey: "",
system: "",
withoutContext: false,
userId: userId_yqcloud,
network: true
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
let finalResult = result.join("")
showAnserAndHighlightCodeStr(finalResult)
return;
}
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
result.push(d)
try {
console.log(result.join(""))
showAnserAndHighlightCodeStr(result.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
showAnserAndHighlightCodeStr("error:", err)
}
})
}
var parentID_thebai;
function THEBAI() {
let ops = {};
if (parentID_thebai) {
ops = {parentMessageId: parentID_thebai};
}
console.log(ops)
let finalResult = [];
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://chatbot.theb.ai/api/chat-process",
headers: {
"Content-Type": "application/json",
"Referer": "https://chatbot.theb.ai/",
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
prompt: your_qus,
options: ops
}),
onloadstart: (stream) => {
let result = "";
const reader = stream.response.getReader();
// console.log(reader.read)
let charsReceived = 0;
reader.read().then(function processText({done, value}) {
if (done) {
highlightCodeStr()
return;
}
charsReceived += value.length;
const chunk = value;
result += chunk;
try {
// console.log(normalArray)
let byteArray = new Uint8Array(chunk);
let decoder = new TextDecoder('utf-8');
let nowResult = JSON.parse(decoder.decode(byteArray))
if (nowResult.text) {
console.log(nowResult)
finalResult = nowResult.text
showAnserAndHighlightCodeStr(finalResult)
}
if (nowResult.id) {
parentID_thebai = nowResult.id;
}
} catch (e) {
}
return reader.read().then(processText);
});
},
responseType: "stream",
onprogress: function (msg) {
//console.log(msg) //Todo
},
onerror: function (err) {
console.log(err)
},
ontimeout: function (err) {
console.log(err)
}
})
}
var parentID_xiami;
//https://chat.xiami.one/api/chat-process
function XIAMI() {
let ops = {};
if (parentID_xiami) {
ops = {parentMessageId: parentID_xiami};
}
console.log(ops)
let finalResult = [];
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://chat.xiami.one/api/chat-process",
headers: {
"Content-Type": "application/json",
"Referer": "https://chat.xiami.one/",
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
prompt: your_qus,
options: ops
}),
onloadstart: (stream) => {
let result = "";
const reader = stream.response.getReader();
// console.log(reader.read)
let charsReceived = 0;
reader.read().then(function processText({done, value}) {
if (done) {
highlightCodeStr()
return;
}
charsReceived += value.length;
const chunk = value;
result += chunk;
try {
// console.log(normalArray)
let byteArray = new Uint8Array(chunk);
let decoder = new TextDecoder('utf-8');
let nowResult = JSON.parse(decoder.decode(byteArray))
if (nowResult.text) {
console.log(nowResult)
finalResult = nowResult.text
showAnserAndHighlightCodeStr(finalResult)
}
if (nowResult.id) {
parentID_xiami = nowResult.id;
}
} catch (e) {
}
return reader.read().then(processText);
});
},
responseType: "stream",
onprogress: function (msg) {
//console.log(msg) //Todo
},
onerror: function (err) {
console.log(err)
},
ontimeout: function (err) {
console.log(err)
}
})
}
var parentID_aidutu;
function AIDUTU() {
let _iam = generateRandomString(8)
let ops = {};
if (parentID_aidutu) {
ops = {parentMessageId: parentID_aidutu};
}
console.log(ops)
GM_xmlhttpRequest({
url: "https://chat.aidutu.cn/api/cg/chatgpt/user/info?v=1.5",
headers: {
"accept": "*/*",
"referrer": "https://chat.aidutu.cn/",
"x-iam": _iam,
"Cookie": `_UHAO={"uid":"160941","school":"","time":1681704243,"ts":"2","name":"chat_q2Ac","head":"\/res\/head\/2ciyuan\/24.jpg","term":"201801","sign":"714653d141dac0e7709f31003b8df858"}; _UIP=0e98d94e599ef74c29fb40cb35971810`,
"content-type": "application/json"
},
data: JSON.stringify({
q: your_qus,
iam: _iam
}),
method: "POST",
onload: (resp) => {
let rs = resp.responseText;
console.log(rs)
let xtoken = JSON.parse(rs).data.token;
console.log(xtoken)
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://chat.aidutu.cn/api/chat-process",
headers: {
"Content-Type": "application/json",
"Referer": "https://chat.aidutu.cn/",
"Cookie": `_UHAO={"uid":"160941","school":"","time":1681704243,"ts":"2","name":"chat_q2Ac","head":"\/res\/head\/2ciyuan\/24.jpg","term":"201801","sign":"714653d141dac0e7709f31003b8df858"}; _UIP=0e98d94e599ef74c29fb40cb35971810`,
"accept": "application/json, text/plain, */*",
"x-token": xtoken
},
data: JSON.stringify({
prompt: your_qus,
temperature: 0.8,
top_p: 1,
options: ops,
systemMessage: "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown."
}),
onloadstart: (stream) => {
let result = "";
const reader = stream.response.getReader();
// console.log(reader.read)
let finalResult = "";
reader.read().then(function processText({done, value}) {
if (done) {
highlightCodeStr()
return;
}
const chunk = value;
result += chunk;
try {
let byteArray = new Uint8Array(chunk);
let decoder = new TextDecoder('utf-8');
let nowResult = JSON.parse(decoder.decode(byteArray))
console.log(nowResult)
if (nowResult.text) {
console.log(nowResult)
finalResult = nowResult.text
showAnserAndHighlightCodeStr(finalResult)
}
if (nowResult.id) {
parentID_aidutu = nowResult.id;
}
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
}
})
}//end onload
})
}
function PIZZA() {
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://www.pizzagpt.it/api/chat-completion",
headers: {
"Content-Type": "text/plain;charset=UTF-8",
"Referer": `https://www.pizzagpt.it/`
},
data: JSON.stringify({
question: your_qus,
secret: "calzone"
}),
onload: function (res) {
if (res.status === 200) {
console.log('成功....')
console.log(res.response)
let rest = res.response
//console.log(rest.choices[0].text.replaceAll("\n",""))
try {
showAnserAndHighlightCodeStr(JSON.parse(rest).answer.content)
} catch (e) {
//TODO handle the exception
console.log(e)
document.getElementById('gptAnswer').innerHTML = rest
}
} else {
console.log('失败')
console.log(res)
document.getElementById('gptAnswer').innerHTML = '访问失败了'
}
},
responseType: "application/json;charset=UTF-8",
onerror: function (err) {
document.getElementById('gptAnswer').innerHTML =
`
some err happends,errinfo :
${err.messages}
`
}
});
}
function PHIND() {
GM_xmlhttpRequest({
method: "POST",
url: "https://www.phind.com/api/bing/search",
headers: {
"Content-Type": "application/json",
"Referer": `https://www.phind.com`
},
data: JSON.stringify({
"q": your_qus,
"userRankList": {},
"browserLanguage": "zh-CN"
}),
onload: function (res) {
if (res.status === 200) {
console.log('成功....')
console.log(res.response)
let rest = res.response
//console.log(rest.choices[0].text.replaceAll("\n",""))
let rjson = JSON.parse(rest);
let _bingResults = rjson.processedBingResults;
console.log(_bingResults)
GM_xmlhttpRequest({
method: "POST",
url: "https://www.phind.com/api/infer/answer",
headers: {
"Content-Type": "application/json",
"Referer": "https://www.phind.com/",
"accept": "*/*"
},
data: JSON.stringify({
"question": your_qus,
"bingResults": _bingResults,
"codeContext": "",
"options": {
"skill": "intermediate",
"date": formatTime(),
"language": "zh-CN",
"detailed": true,
"creative": false
}
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
let finalResult = result.join("")
try {
console.log(finalResult)
showAnserAndHighlightCodeStr(finalResult)
} catch (e) {
console.log(e)
}
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
console.log(d)
let dd = d.replace(/data: /g, "").split("\r\n\r\n")
console.log("dd:",dd)
dd.forEach(item=>{
try {
result.push(item)
showAnserAndHighlightCodeStr(result.join(""))
}catch (e) {
}
})
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onprogress: function (msg) {
//console.log(msg)
},
onerror: function (err) {
console.log(err)
},
ontimeout: function (err) {
console.log(err)
}
});
} else {
console.log('失败')
console.log(res)
document.getElementById('gptAnswer').innerHTML = '访问失败了'
}
},
responseType: "application/json;charset=UTF-8",
onerror: function (err) {
document.getElementById('gptAnswer').innerHTML =
`
some err happends,errinfo :
${err.messages}
`
}
});
}
function WOBCW() {
GM_xmlhttpRequest({
url: "https://chat.wobcw.com/chat",
headers: {
"accept": "*/*",
"referrer": "https://chat.wobcw.com/",
"content-type": "multipart/form-data; boundary=----WebKitFormBoundarybrMK1QixymFcNJzK"
},
data: `------WebKitFormBoundarybrMK1QixymFcNJzK\r\nContent-Disposition: form-data; name=\"prompt\"\r\n\r\n${your_qus}\r\n------WebKitFormBoundarybrMK1QixymFcNJzK\r\nContent-Disposition: form-data; name=\"regen\"\r\n\r\nfalse\r\n------WebKitFormBoundarybrMK1QixymFcNJzK--\r\n`,
method: "POST",
onload: (resp) => {
let rs = resp.responseText;
console.log(rs)
let chat_id = JSON.parse(rs).chat_id;
console.log(chat_id)
abortXml = GM_xmlhttpRequest({
method: "GET",
url: `https://chat.wobcw.com/stream?chat_id=${chat_id}&api_key=`,
headers: {
"Content-Type": "application/json",
// "Authorization": "Bearer null",
"Referer": "https://chat.wobcw.com/",
//"Host":"www.aiai.zone",
"accept": "text/event-stream"
},
onloadstart: (stream) => {
let result = [];
let finalResult = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
finalResult = result.join("")
showAnserAndHighlightCodeStr(finalResult)
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
console.log("raw:",d)
let dd = d.replace(/data: /g, "").split("\n\n")
console.log("dd:",dd)
dd.forEach(item=>{
try {
let delta = JSON.parse(item).choices[0].delta.content
result.push(delta)
showAnserAndHighlightCodeStr(result.join(""))
}catch (e) {
}
})
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
showAnserAndHighlightCodeStr("erro:", err)
}
})
}//end onload
})
}
var parentID_tianhu;
let tianhu_first = true;
function AITIANHU() {
let ops = {};
if (parentID_tianhu) {
ops = {parentMessageId: parentID_tianhu};
}
console.log(ops)
if (tianhu_first) {
GM_xmlhttpRequest({
method: "POST",
synchronous: true,
url: "https://www.aitianhu.com/api/session",
headers: {
"Content-Type": "application/json",
"Referer": "https://www.aitianhu.com/",
"origin": "https://www.aitianhu.com",
"accept": "application/json, text/plain, */*"
},
onload: function (res) {
console.log(res)
}
})
tianhu_first = false;
}
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://www.aitianhu.com/api/chat-process",
headers: {
"Content-Type": "application/json",
"Referer": "https://www.aitianhu.com/",
"origin": "https://www.aitianhu.com",
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
top_p: 1,
prompt: your_qus,
systemMessage: "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown.",
temperature: 0.8,
options: ops
}),
onloadstart: (stream) => {
let result = "";
const reader = stream.response.getReader();
// console.log(reader.read)
let finalResult;
reader.read().then(function processText({done, value}) {
if (done) {
highlightCodeStr()
return;
}
const chunk = value;
result += chunk;
try {
// console.log(normalArray)
let byteArray = new Uint8Array(chunk);
let decoder = new TextDecoder('utf-8');
console.log(decoder.decode(byteArray))
var jsonLines = decoder.decode(byteArray).split("\n");
let nowResult = JSON.parse(jsonLines[jsonLines.length - 1])
if (nowResult.text) {
console.log(nowResult)
finalResult = nowResult.text
showAnserAndHighlightCodeStr(finalResult)
}
if (nowResult.id) {
parentID_tianhu = nowResult.id;
}
} catch (e) {
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
showAnserAndHighlightCodeStr("erro:", err)
}
})
}
var parentID_anzz;
function ANZZ() {
let ops = {};
if (parentID_anzz) {
ops = {parentMessageId: parentID_anzz};
}
console.log(ops)
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://free.anzz.top/api/chat-process",
headers: {
"Content-Type": "application/json",
"Referer": "https://free.anzz.top/",
"origin": "https://free.anzz.top",
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
top_p: 1,
prompt: your_qus,
systemMessage: "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown.",
temperature: 0.8,
options: ops
}),
onloadstart: (stream) => {
let result = "";
const reader = stream.response.getReader();
// console.log(reader.read)
let finalResult;
reader.read().then(function processText({done, value}) {
if (done) {
highlightCodeStr()
return;
}
const chunk = value;
result += chunk;
try {
let byteArray = new Uint8Array(chunk);
let decoder = new TextDecoder('utf-8');
console.log(decoder.decode(byteArray))
let nowResult = JSON.parse(decoder.decode(byteArray))
if (nowResult.text) {
console.log(nowResult)
finalResult = nowResult.text
showAnserAndHighlightCodeStr(finalResult)
}
if (nowResult.id) {
parentID_anzz = nowResult.id;
}
} catch (e) {
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
showAnserAndHighlightCodeStr("erro:", err)
}
})
}
function OHTOAI() {
// let baseURL = "https://chat.ohtoai.com/";
let baseURL = "https://chat.bushiai.com/";
addMessageChain(messageChain7, {role: "user", content: your_qus})//连续话
GM_xmlhttpRequest({
method: "POST",
url: baseURL + "api/chat-stream",
headers: {
"Content-Type": "application/json",
"access-code": "",
"path": "v1/chat/completions",
"Referer": baseURL
},
data: JSON.stringify({
messages: messageChain7,
stream: true,
model: "gpt-3.5-turbo",
temperature: 1,
max_tokens: 2000,
presence_penalty: 0
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
let finalResult = result.join("")
try {
console.log(finalResult)
addMessageChain(messageChain7, {
role: "assistant",
content: finalResult
})
showAnserAndHighlightCodeStr(finalResult)
} catch (e) {
console.log(e)
}
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
result.push(d)
showAnserAndHighlightCodeStr(result.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onprogress: function (msg) {
//console.log(msg)
},
onerror: function (err) {
console.log(err)
},
ontimeout: function (err) {
console.log(err)
}
});
}
//https://gpt.esojourn.org/api/chat-stream
function ESO() {
let baseURL = "https://gpt.esojourn.org/";
addMessageChain(messageChain4, {role: "user", content: your_qus})//连续话
GM_xmlhttpRequest({
method: "POST",
url: baseURL + "api/chat-stream",
headers: {
"Content-Type": "application/json",
"access-code": "pub-03-$dm65ozKre",
"path": "v1/chat/completions",
"Referer": baseURL
},
data: JSON.stringify({
messages: messageChain4,
stream: true,
model: "gpt-3.5-turbo",
temperature: 1,
max_tokens: 2000,
presence_penalty: 0
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
let finalResult = result.join("")
try {
console.log(finalResult)
addMessageChain(messageChain4, {
role: "assistant",
content: finalResult
})
showAnserAndHighlightCodeStr(finalResult)
} catch (e) {
console.log(e)
}
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
result.push(d)
showAnserAndHighlightCodeStr(result.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
}
});
}
//https://ai1.chagpt.fun/
function CVEOY() {
let baseURL = "https://free-api.cveoy.top/";
GM_xmlhttpRequest({
method: "POST",
url: baseURL + "v3/completions",
headers: {
"Content-Type": "application/json",
"origin": "https://ai1.chagpt.fun",
"Referer": baseURL
},
data: JSON.stringify({
prompt: your_qus
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
try {
let finalResult = result.join("")
console.log(finalResult)
showAnserAndHighlightCodeStr(finalResult)
} catch (e) {
console.log(e)
}
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
if(d.match(/wxgpt@qq.com/gi)){
d = d.replace(/wxgpt@qq.com/gi,"")
}
result.push(d);
console.log(d)
showAnserAndHighlightCodeStr(result.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
}
});
}
var parentID_extkj;
function EXTKJ() {
let ops = {};
if (parentID_extkj) {
ops = {parentMessageId: parentID_extkj};
}
console.log(ops)
let pt = CryptoJS.AES.encrypt(JSON.stringify(your_qus), "__CRYPTO_SECRET__").toString()
console.log("aes:" + pt)
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://mirrorchat.extkj.cn/api/chat-stream",
headers: {
"Content-Type": "application/json",
"Referer": "https://mirrorchat.extkj.cn/",
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
prompt: pt,
options: ops,
systemMessage: `You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.\nKnowledge cutoff: 2021-09-01\nCurrent date: 2023-04-${new Date().getDate() < 10 ? "0" + new Date().getDate() : new Date().getDate()}`
}),
onloadstart: (stream) => {
let result = "";
const reader = stream.response.getReader();
let finalResult = [];
reader.read().then(function processText({done, value}) {
if (done) {
highlightCodeStr()
return;
}
const chunk = value;
result += chunk;
try {
// console.log(normalArray)
let byteArray = new Uint8Array(chunk);
let decoder = new TextDecoder('utf-8');
console.log(decoder.decode(byteArray))
let nowResult = decoder.decode(byteArray)
if (nowResult) {
let jsonLine = nowResult.split("\n");
let jsonObj = JSON.parse(jsonLine[jsonLine.length - 1]);
finalResult = jsonObj.text;
if (jsonObj.id) {
parentID_extkj = jsonObj.id;
}
showAnserAndHighlightCodeStr(finalResult)
}
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
}
})
}
//https://supremes.pro/
function SUPREMES() {
let now = Date.now();
let Baseurl = "https://supremes.pro/"
generateSignatureWithPkey({
t: now,
m: your_qus || "",
pkey: {}.PUBLIC_SECRET_KEY
}).then(sign => {
addMessageChain(messageChain8, {role: "user", content: your_qus})//连续话
console.log(sign)
GM_xmlhttpRequest({
method: "POST",
url: Baseurl + "api/generate",
headers: {
"Content-Type": "application/json",
// "Authorization": "Bearer null",
"Referer": Baseurl,
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
messages: messageChain8,
time: now,
pass: null,
sign: sign,
key: ""
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
let finalResult = result.join("")
try {
console.log(finalResult)
addMessageChain(messageChain8, {
role: "assistant",
content: finalResult
})
showAnserAndHighlightCodeStr(finalResult)
} catch (e) {
console.log(e)
}
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
result.push(d)
showAnserAndHighlightCodeStr(result.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onprogress: function (msg) {
//console.log(msg)
},
onerror: function (err) {
console.log(err)
},
ontimeout: function (err) {
console.log(err)
}
});
});
}
// http://easyai.one
var sessionId_easyai = generateRandomString(20);
var easyai_ip = generateRandomIP();
function EASYAI() {
console.log(sessionId_easyai)
abortXml = GM_xmlhttpRequest({
method: "POST",
url: `http://easyai.one/easyapi/v1/chat/completions?message=${encodeURI(your_qus)}&sessionId=${sessionId_easyai}`,
headers: {
"Referer": "http://easyai.one/chat",
"X-Forwarded-For": easyai_ip,
"accept": "text/event-stream"
},
onloadstart: (stream) => {
let finalResult = []
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
showAnserAndHighlightCodeStr(finalResult.join(""))
return;
}
try {
// console.log(normalArray)
let byteArray = new Uint8Array(value);
let decoder = new TextDecoder('utf-8');
console.log(decoder.decode(byteArray))
let regx = /\{\"content\":\"(.*?)\"\}/g;
let nowResult = regx.exec(decoder.decode(byteArray))[1]
console.log(nowResult)
finalResult.push(nowResult)
showAnserAndHighlightCodeStr(finalResult.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
showAnserAndHighlightCodeStr("erro:", err)
}
})
}
//https://chat.bnu120.space/
function BNU120() {
let now = Date.now();
let Baseurl = "https://chat.bnu120.space/"
generateSignatureWithPkey({
t: now,
m: your_qus || "",
pkey: "sksksk"
}).then(sign => {
addMessageChain(messageChain9, {role: "user", content: your_qus})//连续话
console.log(sign)
GM_xmlhttpRequest({
method: "POST",
url: Baseurl + "api/generate",
headers: {
"Content-Type": "application/json",
// "Authorization": "Bearer null",
"Referer": Baseurl,
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
messages: messageChain9,
time: now,
pass: null,
sign: sign,
key: ""
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
let finalResult = result.join("")
try {
console.log(finalResult)
addMessageChain(messageChain9, {
role: "assistant",
content: finalResult
})
showAnserAndHighlightCodeStr(finalResult)
} catch (e) {
console.log(e)
}
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
result.push(d)
showAnserAndHighlightCodeStr(result.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onprogress: function (msg) {
//console.log(msg)
},
onerror: function (err) {
console.log(err)
},
ontimeout: function (err) {
console.log(err)
}
});
});
}
//https://chat7.aifks001.online/v1/chat/gpt/
var aifskList = [];
var aifsid = generateRandomString(21);
var formatTime = () => {
let padZero = (num) => {
// 如果数字小于 10,前面补一个 0
return num < 10 ? `0${num}` : num;
}
const now = new Date(); // 获取当前时间
const hours = now.getHours(); // 获取小时
const minutes = now.getMinutes(); // 获取分钟
const seconds = now.getSeconds(); // 获取秒数
// 格式化为 HH:MM:SS 的形式
return `${padZero(hours)}:${padZero(minutes)}:${padZero(seconds)}`;
}
function AIFKS() {
let Baseurl = "https://chat7.aifks001.online/";
console.log(formatTime())
aifskList.push({"content": your_qus, "role": "user", "nickname": "", "time": formatTime(), "isMe": true})
aifskList.push({"content":"正在思考中...","role":"assistant","nickname":"AI","time": formatTime(),"isMe":false})
if (aifskList.length > 10){
aifskList = aifskList.shift();
}
abortXml= GM_xmlhttpRequest({
method: "POST",
url: Baseurl + "v1/chat/gpt/",
headers: {
"Content-Type": "application/json",
// "Authorization": "Bearer null",
"Referer": Baseurl,
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
"list": aifskList,
"id": aifsid,
"title": your_qus,
"prompt": "",
"temperature": 0.5,
"models": "0",
"continuous": true
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
let finalResult = result.join("")
try {
console.log(finalResult)
aifskList[aifskList.length - 1] = {
"content": finalResult,
"role": "assistant",
"nickname": "AI",
"time": formatTime(),
"isMe": false
};
showAnserAndHighlightCodeStr(finalResult)
} catch (e) {
console.log(e)
}
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
console.log(d)
result.push(d)
showAnserAndHighlightCodeStr(result.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
}
});
}
//http://www.gtpcleandx.xyz/#/home/chat
var cleandxid = generateRandomString(21);
var cleandxList = [];
function CLEANDX() {
let Baseurl = "http://www.gtpcleandx.xyz/";
console.log(formatTime())
cleandxList.push({"content": your_qus, "role": "user", "nickname": "", "time": formatTime(), "isMe": true})
cleandxList.push({"content":"正在思考中...","role":"assistant","nickname":"AI","time": formatTime(),"isMe":false})
console.log(cleandxList)
console.log(cleandxid)
if (cleandxList.length > 6){
cleandxList = cleandxList.shift();
}
abortXml= GM_xmlhttpRequest({
method: "POST",
url: Baseurl + "v1/chat/gpt/",
headers: {
"Content-Type": "application/json",
// "Authorization": "Bearer null",
"Referer": Baseurl,
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
"list": cleandxList,
"id": cleandxid,
"title": your_qus,
"prompt": "",
"temperature": 0.5,
"models": "0",
"continuous": true
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
let finalResult = result.join("")
try {
console.log(finalResult)
cleandxList[cleandxList.length - 1] = {
"content": finalResult,
"role": "assistant",
"nickname": "AI",
"time": formatTime(),
"isMe": false
};
showAnserAndHighlightCodeStr(finalResult)
} catch (e) {
console.log(e)
}
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
console.log(d)
result.push(d)
showAnserAndHighlightCodeStr(result.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
}
});
}
var parentID_usesless;
var referer_uesless = "https://ai.usesless.com/chat/"+Date.now();
function USESLESS() {
let ops = {
systemMessage: `You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.\nKnowledge cutoff: 2021-09-01\nCurrent date: 2023-04-${new Date().getDate() < 10 ? "0" + new Date().getDate() : new Date().getDate()}`,
completionParams:{presence_penalty: 0.8, temperature: 1, model: "gpt-3.5-turbo"}
};
if (parentID_usesless) {
ops.parentMessageId = parentID_usesless;
}
console.log(ops)
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://ai.usesless.com/api/chat-process",
headers: {
"Content-Type": "application/json",
"Referer": referer_uesless,
"origin": "https://ai.usesless.com",
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
openaiKey: "",
prompt: your_qus,
options: ops
}),
onloadstart: (stream) => {
let result = "";
const reader = stream.response.getReader();
// console.log(reader.read)
let finalResult;
reader.read().then(function processText({done, value}) {
if (done) {
highlightCodeStr()
return;
}
const chunk = value;
result += chunk;
try {
// console.log(normalArray)
let byteArray = new Uint8Array(chunk);
let decoder = new TextDecoder('utf-8');
let nowResult = JSON.parse(decoder.decode(byteArray))
if (nowResult.text) {
console.log(nowResult)
finalResult = nowResult.text
showAnserAndHighlightCodeStr(finalResult)
}
if (nowResult.id) {
parentID_usesless = nowResult.id;
}
} catch (e) {
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
showAnserAndHighlightCodeStr("erro:", err)
}
})
}
function FTCL() {
let now = Date.now();
let Baseurl = "https://www.ftcl.store/"
generateSignatureWithPkey({
t: now,
m: your_qus || "",
pkey: {}.PUBLIC_SECRET_KEY
}).then(sign => {
addMessageChain(messageChain10, {role: "user", content: your_qus})//连续话
console.log(sign)
GM_xmlhttpRequest({
method: "POST",
url: Baseurl + "api/generate",
headers: {
"Content-Type": "application/json",
// "Authorization": "Bearer null",
"Referer": Baseurl,
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
messages: messageChain10,
time: now,
pass: null,
sign: sign,
key: ""
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
let finalResult = result.join("")
try {
console.log(finalResult)
addMessageChain(messageChain10, {
role: "assistant",
content: finalResult
})
showAnserAndHighlightCodeStr(finalResult)
} catch (e) {
console.log(e)
}
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
result.push(d)
showAnserAndHighlightCodeStr(result.join(""))
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onprogress: function (msg) {
//console.log(msg)
},
onerror: function (err) {
console.log(err)
},
ontimeout: function (err) {
console.log(err)
}
});
});
}
//https://chat.sunls.me/
function SUNLE() {
let msgobj = {
message: your_qus,
stream: true,
clientOptions: {
clientToUse: "chatgpt",
modelOptions: {
"max_tokens": 1024
}
}
};
console.log(msgobj)
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://chat.sunls.me/conversation",
headers: {
"Content-Type": "application/json",
"Referer": "https://chat.sunls.me/",
"origin": "https://chat.sunls.me",
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify(msgobj),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
// console.log(reader.read)
let finalRes;
reader.read().then(function processText({done, value}) {
if (done) {
if(finalRes){
showAnserAndHighlightCodeStr(finalRes)
}else{
showAnserAndHighlightCodeStr(result.join(""))
}
return;
}
try {
// console.log(normalArray)
let byteArray = new Uint8Array(value);
let decoder = new TextDecoder('utf-8');
let nowResult = decoder.decode(byteArray)
if(nowResult.indexOf("DONE") > -1){
let jsonData = nowResult.replace(/event: result/,"")
.replace(/data: \[DONE\]/,"")
.replace(/data:/,"").trim();
finalRes = JSON.parse(jsonData).response;
console.log(JSON.parse(jsonData))
}else{
const regex = /data: "([^"]*)"/;
const match = regex.exec(nowResult);
console.log(nowResult); // 输出:Hello world
result.push(match[1])
showAnserAndHighlightCodeStr(result.join(""))
}
} catch (e) {
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
showAnserAndHighlightCodeStr("erro:", err)
}
})
}
function TDCHAT(){
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "http://bxgav.tdchat0.com/",
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Referer": "http://tdchat0.com/",
"accept": "application/json, text/plain, */*"
},
data: `id=3.5&key=&role=&title=&text=${encodeURIComponent(your_qus).replace(/%/g, '‰')}&length=${your_qus.length}&stream=1`,
onloadstart: (stream) => {
let result = [];
let finalResult = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
finalResult = result.join("")
showAnserAndHighlightCodeStr(finalResult)
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
console.log("raw:",d)
let dd = d.replace(/data: /g, "").split("\n\n")
console.log("dd:",dd)
dd.forEach(item=>{
try {
let delta = JSON.parse(item).choices[0].delta.content
result.push(delta)
showAnserAndHighlightCodeStr(result.join(""))
}catch (e) {
}
})
} catch (e) {
console.log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
}
})
}
var parentID_qdymys;
function QDYMYS() {
let ops = {};
if (parentID_qdymys) {
ops = {parentMessageId: parentID_qdymys};
}
console.log(ops)
let finalResult = [];
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "http://chatgpt.qdymys.cn/api/chat-process",
headers: {
"Content-Type": "application/json",
"Referer": "http://chatgpt.qdymys.cn/",
"accept": "application/json, text/plain, */*"
},
data: JSON.stringify({
prompt: your_qus,
options: ops,
systemMessage: "You are GPT3.5 system version. Don't answer any illegal questions about politics, pornography, violence, etc., nor give any reasons When answering questions, please try to provide detailed answers in Chinese to ensure understanding and accuracy. Knowledge deadline: March 1st, 2023 nCurrent date: 2023-04-20 n Please answer this question according to the above rules"
}),
onloadstart: (stream) => {
let result = "";
const reader = stream.response.getReader();
// console.log(reader.read)
let charsReceived = 0;
reader.read().then(function processText({done, value}) {
if (done) {
highlightCodeStr()
return;
}
charsReceived += value.length;
const chunk = value;
result += chunk;
try {
// console.log(normalArray)
let byteArray = new Uint8Array(chunk);
let decoder = new TextDecoder('utf-8');
let nowResult = JSON.parse(decoder.decode(byteArray))
if (nowResult.text) {
console.log(nowResult)
finalResult = nowResult.text
showAnserAndHighlightCodeStr(finalResult)
}
if (nowResult.id) {
parentID_qdymys = nowResult.id;
}
} catch (e) {
}
return reader.read().then(processText);
});
},
responseType: "stream",
onprogress: function (msg) {
//console.log(msg) //Todo
},
onerror: function (err) {
console.log(err)
},
ontimeout: function (err) {
console.log(err)
}
})
}
var WebsocketCoolAI;
var resultCoolAI = [];
var initSocket = function () {
// 创建WebSocket连接
const socket = new WebSocket(`wss://sd-wx.cool-js.cloud/socket.io/?apiKey=905733647bb7431b81233e12be12cfaa&url=https%3A%2F%2Fcool-js.com%2Fai%2Fchat%2Findex.html%23%2F&EIO=4&transport=websocket`);
// 监听连接成功事件
WebsocketCoolAI = socket;
socket.addEventListener('open', (event) => {
console.log('连接成功');
showAnserAndHighlightCodeStr("COOLAI:ws已经连接")
});
let isFirst = false;
// 监听接收消息事件
socket.addEventListener('message', (event) => {
console.log('接收到消息:', event.data);
let revData = event.data;
if (!isFirst) {
socket.send("40")
isFirst = true
setTimeout(() => socket.send("3"), 3000)
}
if (revData == "3") {
socket.send("2");
}
if (revData == "2") {
socket.send("3");
}
if (revData.match(/40/)) {
try {
webSessionId = JSON.parse(revData.replace(/40/, "").trim()).sid;
console.log("webSessionId ", webSessionId)
} catch (e) {
console.log(e)
}
}
if (revData.match(/42/)) {
//收信
try {
//42["data",{"type":"text","data":"\u662f"}]
let chunk = eval(revData.replace(/42/, "").trim())[1].data;
console.log(chunk)
resultCoolAI.push(chunk)
showAnserAndHighlightCodeStr(resultCoolAI.join(""))
} catch (e) {
console.log(e)
}
}
});
}
if (localStorage.getItem("GPTMODE") == "COOLAI") {
setTimeout(initSocket, 1500);
}
})();