Toggle Chat

Press X to toggle chat visibility.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        Toggle Chat
// @namespace   Violentmonkey Scripts
// @match       https://*.fishtank.live/*
// @icon        https://www.google.com/s2/favicons?sz=64&domain=fishtank.live
// @version     1.2
// @author      zurrty
// @license     GNU GPLv3
// @run-at      document-idle
// @description Press X to toggle chat visibility.
// ==/UserScript==
'use strict';

function playSound(src) {
  const audio = document.createElement("audio");
  audio.style.display = "none";
  audio.volume = 0.5;
  audio.src = src;
  document.body.appendChild(audio);

  audio.onended = () => {
    audio.remove();
  };
  audio.play();
}

function setVisible(className, show) {
      document.querySelectorAll(className).forEach(el => {
          el.style.display = show ? '' : 'none';
          el.style.width = show ? '' : '0px';
      });
  }

function isInputFocused() {
  const active = document.activeElement;
  return document.activeElement != null && (active.tagName === 'INPUT' || active.tagName === 'TEXTAREA' || active.isContentEditable);
}

let isChat = true;

document.addEventListener("keydown", (e) => {
  if ((e.key === 'x' || e.key === 'X') && !isInputFocused() && !e.repeat) {
    isChat = !isChat;
    setVisible(".layout_right__x_sAY", isChat);
    document.querySelector(".layout_layout__5rz87").style["grid-template-columns"] = isChat ? "" : "var(--left-bar-width) calc(100vw - var(--left-bar-width) - 0px - var(--spacing)) 0px";
    playSound("https://cdn.fishtank.live/sounds/latch-short.wav")
  }
})