C-Nedelcu/talk-to-chatgpt

I fixed the extension not auto-sending messages

Opened this issue · 2 comments

Hey guys, i noticed the extension its not auto-sending the message anymore after you speak to it, i managed to fixed it, there are some things that i need to delete since i was debugging it for a while, but it should be working now! if you are not really comfortable modifying the code feel free to check out my fork on my profile, has everything updated and working fine and you can just download it and install it

if the extension is not auto sending the message after you speak, open content.js and look for function CN_SendMessage(text)
replace the entire function for this one instead:

(feel free to improve it or delete some trash i left there while debugging the issue)

function CN_SendMessage(text) {
    console.log("[CN_SendMessage] Trying to send message: " + text + " ");

    // Find the textarea either by class or id
    var textarea = jQuery('.overflow-hidden textarea');
    if (!textarea.length) {
        textarea = jQuery('#prompt-textarea');
        if (!textarea.length) {
            console.error('Textarea not found');
            return;
        }
    }

    // Focus on the textarea and simulate typing
    textarea.focus();
    var existingText = textarea.val();
    var fullText = existingText ? existingText + ' ' + text : text;
    var event = new Event('input', { bubbles: true });
    textarea.val(fullText)[0].dispatchEvent(event);

    // Adjust the height of the textarea
    var rows = Math.ceil(fullText.length / 88);
    var height = rows * 24;
    textarea.css('height', height + 'px');

    // Find the send button and enable it
    var sendButton = jQuery("[data-testid='fruitjuice-send-button']");
    if (sendButton.length) {
        sendButton.prop('disabled', false); // Force enable
        sendButton.removeAttr('disabled').removeClass('disabled');

        // Ensure the button is enabled and click it
        if (!sendButton.is(':disabled')) {
            sendButton[0].click(); // Attempt to click using DOM API
            console.log("[CN_SendMessage] Automatically clicking the send button.");
        } else {
            console.log("[CN_SendMessage] The send button is enabled but could not be clicked.");
        }
    } else {
        console.error("[CN_SendMessage] Send button not found.");
    }

    // Additional logic for speech recognition, if applicable
    if (CN_SPEECHREC) {
        clearTimeout(CN_TIMEOUT_KEEP_SPEECHREC_WORKING);
        CN_SPEECHREC.stop();
    } else {
        // Continue speech recognition
        clearTimeout(CN_TIMEOUT_KEEP_SPEECHREC_WORKING);
        CN_TIMEOUT_KEEP_SPEECHREC_WORKING = setTimeout(CN_KeepSpeechRecWorking, 100);
    }
}

this worked perfectly for me. thank you so much!

i'm wondering if you're capable of making a new option, to use open ai's built in read aloud function automatically, and the ability to choose from their voices.

@relaxwithadam Sounds like an awesome idea, gonna work on it, right now most updated ver is on my fork, check it out! Im planning to mantain the project and add some cool features lots of guys from here suggested