ChatGPT Automatically Continue Conversations with a given Prompt

This user script enables ChatGPT users to effortlessly and seamlessly continue conversations with a given prompt. This script utilizes the MutationObserver API to detect changes in the DOM and simulates keyboard and mouse events to input and send the prompt automatically. It is designed to be used with the OpenAI ChatGPT interface and should be compatible with most modern web browsers.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name        ChatGPT Automatically Continue Conversations with a given Prompt
// @namespace   Violentmonkey Scripts
// @match       https://chat.openai.com/*
// @grant       none
// @license     MIT
// @version     1.0.1
// @author      Dillon
// @description This user script enables ChatGPT users to effortlessly and seamlessly continue conversations with a given prompt. This script utilizes the MutationObserver API to detect changes in the DOM and simulates keyboard and mouse events to input and send the prompt automatically. It is designed to be used with the OpenAI ChatGPT interface and should be compatible with most modern web browsers.
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function() {
        console.debug('load auto repeat js')
        let cp = prompt('Send a message to sendTextarea', 'Please continue without repeat, ensure that your responses do not contain redundant content or themes from previous responses.') || ''
        console.log(`cp: ${cp}`)

        const sendButton = document.querySelector('button.absolute');
        const sendTextarea = document.getElementById('prompt-textarea');
        console.debug(`sendButton: ${sendButton}`);
        console.debug(`sendTextarea: ${sendTextarea}`);

        const config = { attributes: true, childList: true, subtree: true };

        const callback = function(mutationsList, observer) {

            if (!cp){
              return false
            }

            for(let mutation of mutationsList) {
                if (mutation.type === 'attributes' && mutation.attributeName === 'disabled') {
                    console.debug('Button attribute changed...');
                    if (!sendButton.disabled){
                        console.debug('ChatGPT response is complete. Sending next command...');
                        // 设置textarea的值
                        let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
                        nativeInputValueSetter.call(sendTextarea, cp);

                        let ev2 = new Event('input', { bubbles: true});
                        sendTextarea.dispatchEvent(ev2);

                        // 创建一个新的'keydown'事件
                        // 延迟一段时间,然后模拟Enter键和点击事件
                        setTimeout(function() {
                            // 创建并触发一个键盘事件
                            let event = new KeyboardEvent('keydown', {
                                key: 'Enter'
                            });
                            sendTextarea.dispatchEvent(event);
                            sendTextarea.dispatchEvent(event);

                            // 点击按钮
                            sendButton.click();
                        }, 3000);  // 1000毫秒,或者1秒
                    }
                }

                if (mutation.type === 'childList') {
                    let targetNode = document.querySelector('div.text-2xl');
                    if (!targetNode) {
                        console.debug('Target node is missing...');
                        sendButton.disabled = false;
                    }
                }
            }
        };

        const observer = new MutationObserver(callback);

        observer.observe(document.body, config);
    });
})();