mtslink space2mic

Добавляет на MTS Link возможность включать звук, пока нажата клавиша "Пробел"

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         mtslink space2mic
// @namespace    https://ryzhpolsos.ru/
// @version      0.1
// @description  Добавляет на MTS Link возможность включать звук, пока нажата клавиша "Пробел"
// @author       ryzhpolsos
// @match        https://my.mts-link.ru/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=mts-link.ru
// @grant        none
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(async function(){
    function waitFor(selector){
        return new Promise(res=>{
            let el = document.querySelector(selector);

            if(el){
                res(el);
            }else{
                setTimeout(()=>waitFor(selector).then(e=>res(e)), 100);
            }
        });
    }

    const button = await waitFor('button[data-testid="VCSControlButton.Microfone.Button"]');

    window.addEventListener('keydown', e=>{
        if(e.target.nodeName == 'INPUT' || e.target.nodeName == 'TEXTAREA' || e.target.contentEditable == 'true') return;
        if(e.code == 'Space' && button.querySelector('.icon_mic-off')){
            button.click();
        }
    });

    window.addEventListener('keyup', e=>{
        if(e.target.nodeName == 'INPUT' || e.target.nodeName == 'TEXTAREA' || e.target.contentEditable == 'true') return;
        if(e.code == 'Space' && button.querySelector('.icon_mic-on')){
            button.click();
        }
    });
})();