Copilot Remove Text Limit

Detects and modifies the maxlength of a textarea inside shadow DOM as quickly as possible until it is successfully changed

// ==UserScript==
// @name         Copilot Remove Text Limit
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  Detects and modifies the maxlength of a textarea inside shadow DOM as quickly as possible until it is successfully changed
// @author       unknown
// @match        https://copilot.microsoft.com/*
// @match        https://www.bing.com/chat*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    /**
     * Function to check and modify the maxlength attribute of the textarea
     * @param {Document | ShadowRoot} root - The root element to start searching from
     * @returns {boolean} - Returns true if the maxlength has been successfully modified
     */
    function modifyTextareaMaxlength(root) {
        // Target the specific textarea element by its class and ID
        const textareas = root.querySelectorAll('textarea.text-area#searchbox');
        let modified = false;
        
        textareas.forEach(textarea => {
            if (textarea.maxLength !== 99999999) {
                textarea.maxLength = 99999999;
                console.log(`Modified maxlength of textarea with ID ${textarea.id} to ${textarea.maxLength}`);
                modified = true;
            }
        });

        // Recursively check and modify textareas in shadow DOMs
        const allElements = root.querySelectorAll('*');
        allElements.forEach(element => {
            if (element.shadowRoot) {
                if (modifyTextareaMaxlength(element.shadowRoot)) {
                    modified = true;
                }
            }
        });

        return modified;
    }

    /**
     * Main function to run the modifyTextareaMaxlength function until the textarea is modified
     */
    function monitor() {
        if (modifyTextareaMaxlength(document)) {
            clearInterval(interval);
            console.log('Successfully modified the maxlength. Stopping the script.');
        }
    }

    // Run the monitor function every 100 milliseconds
    const interval = setInterval(monitor, 100); // Reduced interval to 100ms for faster execution
})();