Microphone Toggle Addon

Toggle microphone on double-click

2024-07-28 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

// ==UserScript==
// @name        Microphone Toggle Addon
// @version     1.0
// @description Toggle microphone on double-click
// @author      Bort
// @match       https://tinychat.com/room/*
// @match       https://tinychat.com/*
// @grant       none
// @run-at      document-end
// @namespace https://greasyfork.org/users/1024912
// ==/UserScript==

(function() {
    'use strict';

    // Function to handle double-click on the microphone button
    function toggleMicrophone() {
        let micButton = document.querySelector('button.mic-button'); // Adjust the selector to match the microphone button
        
        if (!micButton) {
            console.error('Microphone button not found');
            return;
        }

        let micState = false; // False: Mic is off, True: Mic is on

        micButton.addEventListener('dblclick', () => {
            micState = !micState;
            if (micState) {
                openMicrophone();
            } else {
                closeMicrophone();
            }
        });
    }

    // Function to open the microphone
    function openMicrophone() {
        let micButton = document.querySelector('button.mic-button'); // Adjust the selector to match the microphone button
        if (micButton) {
            micButton.click();
            console.log('Microphone opened');
        }
    }

    // Function to close the microphone
    function closeMicrophone() {
        let micButton = document.querySelector('button.mic-button'); // Adjust the selector to match the microphone button
        if (micButton) {
            micButton.click();
            console.log('Microphone closed');
        }
    }

    // Initialize the script after the page is fully loaded
    window.addEventListener('load', toggleMicrophone);
})();