ChatGPT ALT+S Voice Toggle (Mic → Checkmark)

ALT+S toggles microphone and submit button (checkmark) in ChatGPT voice mode, alternately triggering them with each press.

当前为 2025-04-20 提交的版本,查看 最新版本

// ==UserScript==
// @name         ChatGPT ALT+S Voice Toggle (Mic → Checkmark)
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  ALT+S toggles microphone and submit button (checkmark) in ChatGPT voice mode, alternately triggering them with each press.
// @author       Kamil
// @match        https://chatgpt.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    let toggleState = false; // false = microphone, true = checkmark

    function clickMicrophone() {
        const micSvg = document.querySelector('.btn-primary > div:nth-child(1) > svg:nth-child(1)');
        const micButton = micSvg?.closest('button');
        if (micButton) {
            micButton.click();
            console.log('🎤 Microphone button clicked.');
        } else {
            console.warn('❌ Microphone button not found.');
        }
    }

    function clickCheckmark() {
        const path = document.querySelector('svg.icon-lg:nth-child(1) > path:nth-child(1)');
        const checkmarkButton = path?.closest('button');
        if (checkmarkButton) {
            checkmarkButton.click();
            console.log('✅ Checkmark button clicked.');
        } else {
            console.warn('❌ Checkmark button not found.');
        }
    }

    document.addEventListener('keydown', function (e) {
        if (e.altKey && !e.ctrlKey && !e.shiftKey && e.code === 'KeyS') {
            e.preventDefault();

            if (!toggleState) {
                clickMicrophone(); // First press → microphone
            } else {
                clickCheckmark(); // Second press → checkmark
            }

            toggleState = !toggleState; // Toggle state
        }
    });
})();