add spectate toggle

since talkomatic currently doesnt have a spectate toggle, you can switch your spectate mode while in a room

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name        add spectate toggle
// @namespace   Violentmonkey Scripts
// @icon        https://classic.talkomatic.co/images/icons/favicon.png
// @version     1.0.0
//
// @match       https://classic.talkomatic.co/room.html*
// @grant       none
//
// @author      paul
// @description since talkomatic currently doesnt have a spectate toggle, you can switch your spectate mode while in a room
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to inject the requested HTML into the top-navbar
    function injectButton(navbar) {
        // Prevent duplicate injections if the script runs multiple times
        if (document.getElementById('tm-spectate-toggle-btn')) return;

        const buttonContainer = document.createElement('div');
        buttonContainer.id = 'tm-spectate-toggle-btn';
        buttonContainer.style.display = 'inline-block';
        buttonContainer.style.margin = '0 5px';

        // Injected HTML block matching your exact button logic
        buttonContainer.innerHTML = `
            <button onmousedown="if (location.search.match('spectate')) {location.assign(\`room.html?roomId=\${currentRoomId}\`)} else {location.assign(\`room.html?roomId=\${currentRoomId}&spectate=1\`)}">
                Toggle Spectate
            </button>
        `.trim();

        navbar.appendChild(buttonContainer);
    }

    // Observer to find nav "top-navbar" inside div "page-container" dynamically
    const observer = new MutationObserver((mutations, obs) => {
        const pageContainer = document.querySelector('div.page-container, #page-container');
        if (pageContainer) {
            const navbar = pageContainer.querySelector('nav.top-navbar, #top-navbar');
            if (navbar) {
                injectButton(navbar);
                // Keep observing in case the site handles client-side re-renders,
                // but we prevent duplicate inserts using the 'tm-spectate-toggle-btn' check.
            }
        }
    });

    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });
})();