Save & Submit keyboard shortcut for ChatGPT

Press Alt + Enter to auto-click the Save & Submit button for Superpower ChatGPT and OpenAI

Versione datata 20/02/2024. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Save & Submit keyboard shortcut for ChatGPT
// @description  Press Alt + Enter to auto-click the Save & Submit button for Superpower ChatGPT and OpenAI
// @author       NWP
// @namespace    https://greatest.deepsurf.us/users/877912
// @version      0.1
// @license      MIT
// @match        https://chat.openai.com/*
// @grant        none
// ==/UserScript==

document.addEventListener('keydown', function(event) {
    if (event.altKey && event.keyCode == 13) {
        const save_submit_openAIButton = document.querySelector("div > button.btn.relative.btn-primary.mr-2");
        const save_submit_superpowerChatGPTButton = document.querySelector("div > button.btn.flex.justify-center.gap-2.btn-primary.mr-2");
        (save_submit_openAIButton || save_submit_superpowerChatGPTButton).click();
    }
});


/*

TODO: to make it easy to find for which operating mode the save_and_submit_button has become obsolete
detect if Superpower ChatGPT is enabled for Chrome and Firefox.

This only works for Chrome within a userscript:

const extensionId = 'amhmeenmapldpjdedekalnfifgnpfnkc';
const resourcePath = 'icons/info.png'; // This works
//const resourcePath = 'manifest.json'; // This doesn't work due to restrictions
const imgUrl = `chrome-extension://${extensionId}/${resourcePath}`;

fetch(imgUrl)
    .then(response => {
        if(response.ok) console.log('Extension installed:', true);
        else throw new Error('Resource not accessible');
    })
    .catch(error => console.log('Extension installed:', false));

Since Firefox doesn't have a similar method that I know of, it's better to
check for an element that has been injected by Superpower ChatGPT (Auto Sync ON/ OFF)
for both Chrome and Firefox.

*/