ChatGPT Auto Prompt Sender

Automates sending of next pre-filled prompt in ChatGPT after current response completion.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         ChatGPT Auto Prompt Sender
// @namespace    https://userscript.moukaeritai.work/
// @version      1.0.0.20231004
// @description  Automates sending of next pre-filled prompt in ChatGPT after current response completion.
// @author       Takashi SASAKI (https://twitter.com/TakashiSasaki)
// @match        https://chat.openai.com/c/*
// @match        https://chat.openai.com
// @icon         https://www.google.com/s2/favicons?sz=64&domain=openai.com
// @supportURL   https://greasyfork.org/ja/scripts/472713
// @license      MIT
// ==/UserScript==

setTimeout(function() {
    'use strict';

    const div = document.querySelector("div:has(>form.stretch)");

    const observer = new MutationObserver((mutationList, observer)=>{
        for(let mutation of mutationList){
            if(mutation.target.querySelector("div.absolute.right-2")){
                mutation.target.querySelector("div.absolute.right-2").style.background = "yellow";
                mutation.target.querySelector("div.absolute.right-2").addEventListener("click", clickEvent=>{
                    if(mutation.target.querySelector("textarea").style.background === "red") {
                        mutation.target.querySelector("textarea").style.background = null;
                    } else {
                        mutation.target.querySelector("textarea").style.background = "red";
                    }//if
                });
                return;
            }//if
            if(mutation.target.querySelector("button.absolute")){
                if(mutation.target.querySelector("textarea").style.background === "red"){
                    setTimeout(()=> mutation.target.querySelector("button.absolute").click(), 1000);
                }//if
                mutation.target.querySelector("textarea").style.background = null;
            }//if
        }//for
    });

    observer.observe(div, {attributes: true,
                           childList: true,
                           subtree: true
                          });
}, 1000);