Skip to content
Snippets Groups Projects
bbb-echotest-autojoin.user.js 2.27 KiB
Newer Older
  • Learn to ignore specific revisions
  • Daniel Müller's avatar
    Daniel Müller committed
    // ==UserScript==
    // @name         BBB Echotest Autojoin
    
    Daniel Müller's avatar
    Daniel Müller committed
    // @version      0.2.1
    
    Daniel Müller's avatar
    Daniel Müller committed
    // @website      https://code.fbi.h-da.de/istddmue2/bbb-echotest-autojoin-userscript
    // @downloadURL  https://code.fbi.h-da.de/istddmue2/bbb-echotest-autojoin-userscript/-/raw/master/bbb-echotest-autojoin.user.js
    // @updateURL    https://code.fbi.h-da.de/istddmue2/bbb-echotest-autojoin-userscript/-/raw/master/bbb-echotest-autojoin.user.js
    // @description  Automatically accept the echotest and automatically mute after connect
    // @author       Daniel Müller
    // @match        https://*.h-da.de/html5client/join*
    // @grant        none
    // ==/UserScript==
    
    async function sleep(ms) {
        await new Promise(r => setTimeout(r, ms));
    }
    
    function getEchotestAcceptButton() {
        let selector = "span[class^=echoTest] > button > span[class*=success]";
        return document.querySelector(selector)?.parentElement;
    }
    
    function getMuteButton() {
        return document.querySelector("button > span > i[class*=icon-bbb-unmute]")?.parentElement?.parentElement;
    }
    
    function getUnmuteButton() {
        return document.querySelector("button > span > i[class*=icon-bbb-mute]")?.parentElement?.parentElement;
    }
    
    function isMuted() {
        if (getMuteButton() != null) return false;
        if (getUnmuteButton() != null) return true;
        return null;
    }
    
    (async function() {
        'use strict';
    
        let waitTime = 100;
    
        // Loop to catch reconnects without reloading the page
        while (true) {
    
            // Wait until the echotest accept button shows up
            while (getEchotestAcceptButton() == null) {
                await sleep(waitTime);
            }
    
            getEchotestAcceptButton().click();
    
    
    Daniel Müller's avatar
    Daniel Müller committed
            let tStart = new Date();
    
            // Force mute for 2.5 seconds after joining
            while (new Date() - tStart < 2500) {
    
    Daniel Müller's avatar
    Daniel Müller committed
    
    
    Daniel Müller's avatar
    Daniel Müller committed
                // Ensure that the microphone is muted after joining
    
    Daniel Müller's avatar
    Daniel Müller committed
                while (isMuted() == false) {
    
    Daniel Müller's avatar
    Daniel Müller committed
                    getMuteButton()?.click();
    
    Daniel Müller's avatar
    Daniel Müller committed
                    await sleep(500);
    
    Daniel Müller's avatar
    Daniel Müller committed
    
    
    Daniel Müller's avatar
    Daniel Müller committed
                await sleep(100);
            }
    
    
    Daniel Müller's avatar
    Daniel Müller committed
            // Ensure that the microphone is muted after joining
            while (isMuted() == false) {
                getMuteButton()?.click();
                await sleep(500);
            }
    
    
    
    Daniel Müller's avatar
    Daniel Müller committed
            // Increase the waitTime after the initial connection
            waitTime = 500;
            await sleep(waitTime);
    
        }
    
    
    Daniel Müller's avatar
    Daniel Müller committed
    })();