版本: 1.5.0已启动,部分需要魔法。当前线路: ${localStorage.getItem("GPTMODE") ? localStorage.getItem("GPTMODE") : "Default"}
`
resolve(divE)
})
}
async function pivElemAddEventAndValue(append_case) {
var search_content
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) {
search_content = document.querySelector(
"#tsf > div:nth-child(1) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input:nth-child(3)"
).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;
}
}
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('changMode').addEventListener('click', () => {
document.getElementById("gptAnswer").innerText = "正在切换模式..."
let chatList = ["Default", "CHATGPT", "EXTKJ", "THEBAI", "YQCLOUD", "AIDUTU", "LTXUK", "51GPT", "TDCHAT", "XEASY", "WGK", "LEILUAN", "AILS", "LERSEARCH", "COOLAI"]
let GPTMODE = localStorage.getItem("GPTMODE")
if (GPTMODE) {
let idx = 0;//Default
for (let i = 0; i < chatList.length; i++) {
if (chatList[i] == GPTMODE) {
idx = (i + 1 >= chatList.length) ? 0 : i + 1;
}
}
if(chatList[idx]=="COOLAI"){
initSocket();
}
localStorage.setItem("GPTMODE", chatList[idx])
document.getElementById("gptAnswer").innerText = `切换成功,当前模式:${chatList[idx]}`
} else {
//不存在默认CHATGPT
localStorage.setItem("GPTMODE", "CHATGPT")
document.getElementById("gptAnswer").innerText = "切换成功,当前模式:CHATGPT模式"
}
})
}
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;
}
function LEILUAN() {
console.log(CryptoJS.MD5(your_qus).toString().toLowerCase())
//这里填你的cookie里面的token 地址:https://aichat.leiluan.cc/static/html/pc.html
let leiluanToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwd2QiOiJkNDFkOGNkOThmMDBiMjA0ZTk4MDA5OThlY2Y4NDI3ZSIsImlzcyI6ImFpY2hhdC5sZWlsdWFuLmNjIiwiYXVkIjoiYWljaGF0LmxlaWx1YW4uY2MiLCJpYXQiOjE2ODAyNDY1MTgsIm5iZiI6MTY4MDI0NjUxOCwiZXhwIjoxNjgyODM4NTE4LCJqdGkiOnsiaWQiOjg0LCJ0eXBlIjoiYXBpIn19.1Z3oNWp0mi-GJALHdonBwnm4-jiOHRfu3edj4hH6Evs";
GM_xmlhttpRequest({
url: "https://aichat.leiluan.cc/api/user/openchat",
headers: {
"accept": "*/*",
"authori-zation": `Bearer ${leiluanToken}`,
"referrer": "https://aichat.leiluan.cc/pages/lei_luan/content/talk?content=%E4%BD%A0%E6%98%AF%E4%BB%80%E4%B9%88%E5%9E%83%E5%9C%BE",
"content-type": "application/json"
},
data: JSON.stringify({
prompt: your_qus,
chatlogid: CryptoJS.MD5(your_qus).toString().toLowerCase()
}),
method: "POST",
onload: (resp) => {
let rs = resp.responseText;
let tk = JSON.parse(rs).data.token;
GM_xmlhttpRequest({
url: "https://chat.gptservice.xyz/indext.php?token=" + tk,
method: "GET",
headers: {
"accept": "text/event-stream",
"content-type": "text/event-stream",
"referrer": "https://aichat.leiluan.cc/"
},
onloadstart: (stream) => {
const reader = stream.response.getReader();
let chunks = [];
reader.read().then(function processText({done, value}) {
if (done) {
// 数据已经被完全消耗
const targetString = chunks.join("");
const regExp = /"content":"(.+?)"/gi;
const matchResult = targetString.match(regExp);
let finalAns = []
matchResult.forEach(item => {
try {
console.log("====" + /"content":"(.+?)"/g.exec(item)[1] + "=====")
finalAns.push(/"content":"(.+?)"/g.exec(item)[1])
} catch (e) {
console.error(e, item)
}
})
// console.log(finalAns.join(""))
showAnserAndHighlightCodeStr(finalAns.join(""))
return;
}
try {
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
//console.log(d)
chunks.push(d)
} catch (e) {
console.error(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onerror: function (err) {
console.log(err)
}
})
}
})
}
var messageChain2 = [];//AILS
var messageChain4 = [];//LTXUK
var messageChain5 = [];//XEASY
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://ai5.wuguokai.top/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",
headers: {
"Content-Type": "application/json",
"Referer": "https://chat8.yqcloud.top/",
"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_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.3",
headers: {
"accept": "*/*",
"referrer": "https://aichat.leiluan.cc/",
"x-iam:": _iam,
"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/",
"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 LTXUK() {
let now = Date.now()
const pk = {}.PUBLIC_SECRET_KEY;
generateSignatureWithPkey({
t: now,
m: your_qus || "",
pkey: pk
}).then(sign => {
console.log(sign)
addMessageChain(messageChain4, {role: "user", content: your_qus})//连续话
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://luntianxia.uk/api/generate",
headers: {
"Content-Type": "application/json",
"Referer": `https://luntianxia.uk/`
},
data: JSON.stringify({
messages: messageChain4,
time: now,
pass: null,
sign: sign
//key: "",
//usage: Math.floor(Math.random() * 8) + 1
}),
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 {
log(rest)
showAnserAndHighlightCodeStr(rest)
addMessageChain(messageChain4, {
role: "assistant",
content: rest
})
} catch (e) {
//TODO handle the exception
console.log(e)
document.getElementById('gptAnswer').innerHTML = `${rest}`
}
highlightCodeStr()
} else {
console.log('失败')
console.log(res)
document.getElementById('gptAnswer').innerHTML = '访问失败了'
}
},
responseType: "application/json;charset=UTF-8",
onprogress: function (msg) {
//console.log(msg) //Todo
},
onerror: function (err) {
document.getElementById('gptAnswer').innerHTML =
`
some err happends,errinfo :
${err.messages}
`
},
ontimeout: function (err) {
document.getElementById('gptAnswer').innerHTML =
`
Opps!TimeOut,Please try again,errinfo:
${err.messages}
`
}
});
});
}
function XEASY() {
let now = Date.now()
const pk = {}.PUBLIC_SECRET_KEY;
generateSignatureWithPkey({
t: now,
m: your_qus || "",
pkey: pk
}).then(sign => {
console.log(sign)
addMessageChain(messageChain5, {role: "user", content: your_qus})//连续话
abortXml = GM_xmlhttpRequest({
method: "POST",
url: "https://chat6.xeasy.me/api/generate",
headers: {
"Content-Type": "application/json",
"Referer": `https://chat6.xeasy.me/`
},
data: JSON.stringify({
messages: messageChain5,
time: now,
pass: null,
sign: sign
//key: "",
//usage: Math.floor(Math.random() * 8) + 1
}),
onloadstart: (stream) => {
let result = [];
const reader = stream.response.getReader();
reader.read().then(function processText({done, value}) {
if (done) {
let finalResult = result.join("")
console.log(finalResult)
showAnserAndHighlightCodeStr(finalResult)
addMessageChain(messageChain5, {
role: "assistant",
content: finalResult
})
return;
}
let d = new TextDecoder("utf8").decode(new Uint8Array(value));
result.push(d)
try {
showAnserAndHighlightCodeStr(result.join(""))
} catch (e) {
log(e)
}
return reader.read().then(processText);
});
},
responseType: "stream",
onprogress: function (msg) {
//console.log(msg) //Todo
},
onerror: function (err) {
document.getElementById('gptAnswer').innerHTML =
`
some err happends,errinfo :
${err.messages}
`
},
ontimeout: function (err) {
document.getElementById('gptAnswer').innerHTML =
`
Opps!TimeOut,Please try again,errinfo:
${err.messages}
`
}
});
});
}
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);
}
})();