GPT Dictation Toggle (Alt+S) - Stable Edition

Toggles voice dictation in ChatGPT using Alt+S (works even after browser restarts)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         GPT Dictation Toggle (Alt+S) - Stable Edition
// @namespace    http://tampermonkey.net/
// @version      4.1
// @description  Toggles voice dictation in ChatGPT using Alt+S (works even after browser restarts)
// @author       Kamil
// @match        https://chatgpt.com/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    /**
     * Toggles between voice dictation start and stop buttons.
     * - If dictation is not active, starts it.
     * - If dictation is active, stops it.
     */
    function toggleVoiceDictation() {
        const startBtn = document.querySelector('button.composer-btn[aria-label="Dictate button"]');
        const stopBtn = document.querySelector('button.composer-btn[aria-label="Submit dictation"]');

        if (stopBtn) {
            stopBtn.click();
            console.log("🛑 Voice dictation stopped.");
        } else if (startBtn) {
            startBtn.click();
            console.log("🎤 Voice dictation started.");
        } else {
            console.warn("❌ No dictation button found (neither start nor stop).");
        }
    }

    /**
     * Listens for Alt+S to trigger the voice toggle.
     */
    document.addEventListener('keydown', function (e) {
        if (e.altKey && e.key.toLowerCase() === 's') {
            e.preventDefault();
            toggleVoiceDictation();
        }
    });

    console.log("✅ OpenAI Voice Toggle (Alt+S) script loaded.");
})();