Toggle Chat

Press X to toggle chat visibility.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

// ==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")
  }
})