让ChatGPT在中断回答的时候自动输入「请接上文继续」并发送

一、脚本内容

让ChatGPT在中断回答的时候自动输入「请接上文继续」并发送

// ==UserScript==
// @name         ChatGPT自动接上文继续
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  让ChatGPT在中断回答的时候自动输入「请接上文继续」并发送
// @author       yedsn
// @match        https://chat.openai.com/chat*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=openai.com
// @grant        none
// @license MIT
// ==/UserScript==

// ==UserScript==
// @name         ChatGPT自动接上文继续
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  让ChatGPT在中断回答的时候自动输入「请接上文继续」并发送
// @author       yedsn
// @match        https://chat.openai.com/chat*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=openai.com
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    let autoSendFlag = false;
    let checkboxContainer = null;

    // 创建checkbox
    (function generateCheckbox() {

        // 创建checkbox
        checkboxContainer = document.createElement('button');
        checkboxContainer.classList.add('btn', 'btn-autosend', 'relative', 'border-0', 'md:border');
        checkboxContainer.style.fontSize = '.875rem';
        checkboxContainer.style.lineHeight = '1.25rem';
        const checkboxLabel = document.createElement('label');
        const checkbox = document.createElement('input');
        checkbox.style.marginRight = ".5rem";
        checkbox.type = 'checkbox';
        checkbox.id = 'auto-operate-checkbox';
        checkboxLabel.appendChild(checkbox);
        const label = document.createTextNode('中断后自动发送“请接上文继续”');
        checkboxLabel.appendChild(label);
        checkboxContainer.appendChild(checkboxLabel);

        checkbox.addEventListener('change', function() {
            autoSendFlag = this.checked;
        });

        // 添加样式
        const checkboxStyle = `
<style>
.dark .btn-autosend {
    --tw-border-opacity: 1;
    --tw-bg-opacity: 1;
    --tw-text-opacity: 1;
    background-color: rgba(52,53,65,var(--tw-bg-opacity));
    border-color: rgba(86,88,105,var(--tw-border-opacity));
    color: rgba(217,217,227,var(--tw-text-opacity));
}
.light .btn-autosend {
    background-color: rgba(255,255,255,1);
    border-color: rgba(0,0,0,.1);
    color: rgba(64,65,79,1);
}
</style>
        `;
        document.body.insertAdjacentHTML('beforeend', checkboxStyle);



    })();

    // 创建一个 MutationObserver 实例,监听 body 元素内子元素的变化
    const observer = new MutationObserver(function(mutations) {

        // document.body.appendChild(checkboxContainer);
        if(!document.getElementById("auto-operate-checkbox")) {
            const btnNeutral = document.querySelector('.btn-neutral');
            if(btnNeutral) {
                btnNeutral.parentNode.insertBefore(checkboxContainer, btnNeutral);
            }
        }


        if(autoSendFlag) {
            // 执行自动发送
            const button = document.querySelector('.btn-neutral');
            if (!button || button.querySelector('div').textContent.trim() != "Stop generating") {
                // debugger

                // 找到页面中最后一个不为 __next-route-announcer__ 的 p 元素
                const paragraphs = Array.from(document.getElementsByTagName('p'));
                const lastParagraph = paragraphs.filter(p => p.id !== '__next-route-announcer__').pop();

                // 检查最后一个 p 元素内容是否以中文句号结尾
                if (lastParagraph && !lastParagraph.parentNode.classList.contains('result-streaming') && !/\。$/.test(lastParagraph.textContent.trim())) {
                    setTimeout(function () {
                        // 找到 textarea 元素,并填充内容为 "请接上文继续"
                        const textarea = document.querySelector('textarea');
                        textarea.value = '请接上文继续';

                        // 找到与 textarea 同级的 button 元素,并点击它
                        const siblingButton = textarea.nextElementSibling;
                        siblingButton.click();
                    }, Math.floor(Math.random() * (3000 - 500 + 1) + 500));
                }


            }
        }
    });

    const observerConfig = { childList: true, subtree: true };
    observer.observe(document.body, observerConfig);

})();

二、使用方法

脚本功能

用于CHATGPT简单回复的自动化继续

目前v0.2版实现功能

1.在右上角产生一个功能开关

2.开启后,将自动在对话框中回复“继续”

3.判断结尾是否出现抱歉、对不起字眼,发现后关闭。

脚本安装

一、安装油猴脚本管理器插件

如果有条件,可以直接在谷歌Chrome商店下载安装。

如果无法访问,点击下面链接下载Tampermonkey油猴脚本管理器插件的安装包,解压之后,再将crx文件安装到你的谷歌浏览器上,具体可参考这篇文章

最新油猴插件下载

tampermonkey(油猴插件)

立即查看

二、安装脚本

大家先下载本文的脚本离线文件,然后启动脚本编辑器,点击浏览器工具栏上的油猴插件图标,打开【添加新脚本】,将下载的 js 格式的脚本安装文件,拖拽到已清空的编辑器中,保存即可。

脚本更新地址:

https://kdown.fkxz.cn/wp-content/uploads/2023/03/1680061851-35369-chatgptzidongjieshangwen.js

相关文章

 

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

《代码爱好者》

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值