Hide/Show Chat

Hide or show chat on multiplayerpiano.com

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Hide/Show Chat
// @namespace    Hiding and Showing chat, "1" hide, "2", "4" hold 2500 ms show
// @author       Clyde
// @version      1.0
// @description  Hide or show chat on multiplayerpiano.com
// @include      *://multiplayerpiano.com/*
// @include      *://mppclone.com/*
// @include      *://mpp.lapishusky.dev/*
// @include      *://mpp.hyye.tk/*
// @grant        none
// @license      GitHuberII
// ==/UserScript==

(function() {
    'use strict';

    // Function to hide the chat
    function hideChat() {
        var chatElement = document.getElementById('chat');
        if (chatElement) {
            chatElement.style.display = 'none';
        }
    }

    // Function to show the chat
    function showChat() {
        var chatElement = document.getElementById('chat');
        if (chatElement) {
            chatElement.style.display = 'block';
        }
    }

    // Keydown event listener
    document.addEventListener('keydown', function(event) {
        if (event.key === '1') {
            hideChat();
        }
        if (event.key === '2' && event.repeat) {
            var timeout = 2500; // 2500 miliseconds
            var timer;

            // Function to add or restore the chat
            function addOrRestoreChat() {
                clearTimeout(timer);
                showChat();
            }

            // Restore the chat when "S" and "C" are hold for 2500 miliseconds
            if (event.key === '2') {
                timer = setTimeout(addOrRestoreChat, timeout);
            }
            if (event.key === '4') {
                clearTimeout(timer);
            }
        }
    });
})();