Chatgpt query inserter

Insert Text from query parameters into chatgpt textarea and confirm

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Chatgpt query inserter
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Insert Text from query parameters into chatgpt textarea and confirm
// @author       Manimo
// @match        https://chat.openai.com/*
// @grant        none
// @license GPL3
// ==/UserScript==

(function() {
    'use strict';

    function getQueryParam(name) {
        const urlSearchParams = new URLSearchParams(window.location.search);
        return urlSearchParams.get(name);
    }

    function waitForElement(selector, callback) {
        const element = document.querySelector(selector);

        if (element) {
            callback(element);
        } else {
            setTimeout(() => waitForElement(selector, callback), 500);
        }
    }

    function clickButton(textarea) {
        const button = textarea.nextElementSibling;
        if (button) {
            button.click();
            console.log('Tampermonkey script: Button clicked');
        } else {
            console.log('Tampermonkey script: Button not found');
        }
    }

    function insertTaskIntoTextarea() {
        const task = getQueryParam('task');
        console.log('Tampermonkey script: Insert Task into Textarea - Running');

        if (task) {
            console.log(`Tampermonkey script: Task value found: ${task}`);
            waitForElement('textarea', (textarea) => {
                textarea.value = task;
                textarea.dispatchEvent(new Event('input', { bubbles: true }));
                console.log('Tampermonkey script: Task value inserted into textarea');

                // Wait for 500 milliseconds before clicking the button
                setTimeout(() => {
                    clickButton(textarea);
                }, 500);
            });
        } else {
            console.log('Tampermonkey script: Task value not found');
        }
    }

    // Wait for 1.5 seconds before starting the whole script
    setTimeout(() => {
        insertTaskIntoTextarea();
    }, 1500);
})();