Greasy Fork

Greasy Fork is available in English.

chatGPT tools Plus ++

chatGPT in bing!

当前为 2022-12-06 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         chatGPT tools Plus ++
// @namespace    http://tampermonkey.net/
// @version      0.0.1
// @description  chatGPT in bing!
// @author       Onion
// @match        https://cn.bing.com/*
// @require      https://cdn.staticfile.org/jquery/3.4.0/jquery.min.js
// @require      https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js

// @grant       GM_xmlhttpRequest
// @grant       GM_addStyle
// @icon         https://www.google.com/s2/favicons?sz=64&domain=openai.com
// @license    MIT
// ==/UserScript==
(function() {
    'use strict';
    //重要声明:感谢隔壁作者:zhengbangbo (https://github.com/zhengbangbo/chat-gpt-userscript)的请求处理方式,之前一直不知道怎么处理SSE响应,原来直接就可以用一般的方式来接收,那么对返回数据处理切割就直接借鉴啦!(反正MIT不是嘛)
    //cookie 大家自己想办法弄到,别霍霍我了呜呜
    //对返回结果增加了markdown解析成html
    // 请在上面 留 白 处 添加一句:油猴因为策略问题没法增加这个js
    // @require    https://cdn.jsdelivr.net/npm/marked/marked.min.js
    
    const your_cookie=``

    var divE = document.createElement('div');
    var divId = document.createAttribute("id"); //创建属性
    divId.value = 'gptDiv'; //设置属性值
    divE.setAttributeNode(divId); //给div添加属性
    var pE = document.createElement('p');
    var pClass= document.createAttribute('class');
    pClass.value = 'textClass';
    pE.setAttributeNode(pClass)
    var pText = document.createTextNode("chatGPT tools Plus ++ v0.0.1已启动");
    pE.appendChild(pText);
    divE.appendChild(pE);
    document.getElementById('b_context').appendChild(divE)
    document.getElementById('gptDiv').innerHTML=`
<div>
<input id="gptInput" type=text><button id="button_GPT" >chat一下</button><p>openAI已经就绪,请输入你的问题</p></input>
</div>
<div id="gptAnswer">chatGPT tools Plus ++ v0.0.1已启动</div>
`
     document.getElementById('gptDiv').style.background="#ffffffcc"
    document.getElementById('gptDiv').style.backdropFilter="blur(5px)"
    document.getElementById('gptDiv').style.width="452px"
    document.getElementById('gptDiv').style.translate="-20px"
    GM_addStyle(`
    #gptAnswer{
    margin: 0px;
    }
    #gptInput{
    width:74%;
    border-radius: 4px;
    }
    #button_GPT:hover{
    background:#ffffffcc;
    }
    #gptDiv{
        border-radius: 8px;
    padding: 10px;
    }
    #button_GPT{
    translate
    }
    #button_GPT{
    background: transparent;
    translate: 10px 3px;
    border-radius: 3px;
    }
    `)
    var your_qus

    document.getElementById('button_GPT').addEventListener('click',()=>{
        your_qus=document.getElementById("gptInput").value
        do_it()

    })
    function do_it(){
        document.getElementById('gptAnswer').innerHTML=`Loading....`
        GM_xmlhttpRequest({
            method: "POST",
            url: "https://chat.openai.com/backend-api/conversation",
            headers: {
                "Content-Type": "application/json",
                Authorization: `${your_cookie}`,
            },
            data: JSON.stringify({//抓包conversation就可以看到这个结构
                action: "next",
                messages: [
                    {
                        id: uuid(),
                        role: "user",
                        content: {
                            content_type: "text",
                            parts: [your_qus],
                        },
                    },
                ],
                model: "text-davinci-002-render",
                parent_message_id: uuid(),
            }),

            onloadend: function (data) {
                if (data.response) {
                    const answer = JSON.parse(data.response.split("\n\n").slice(-3, -2)[0].slice(6)).message.content.parts[0]
                    document.getElementById('gptAnswer').innerHTML=marked.parse(answer)//markdown 解析HTML
                }
            },

            onerror: function (err) {
                console.log(err)
            },
            ontimeout: function (err) {
                console.log(err)
            }
        })

    }
    function uuid() { //uuid 产生
        var s = [];
        var hexDigits = "0123456789abcdef";
        for (var i = 0; i < 36; i++) {
            s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
        }
        s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
        s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
        s[8] = s[13] = s[18] = s[23] = "-";

        var uuid = s.join("");
        return uuid;
    }

})();