YouTube - Hide chats by default

Hide chats on YouTube live videos by default.

Ajankohdalta 9.9.2024. Katso uusin versio.

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

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.

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

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

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         YouTube - Hide chats by default
// @namespace    amekusa.yt-hide-chats
// @author       amekusa
// @version      1.0.0
// @description  Hide chats on YouTube live videos by default.
// @match        https://www.youtube.com/*
// @run-at       document-start
// @grant        none
// @license      MIT
// @homepage     https://github.com/amekusa/monkeyscripts
// ==/UserScript==

(function (doc) {
	// --- config ---
	let interval = 1000;
	let debug = true ? console.debug : (() => {});
	// --------------

	let watcher;

	let update = () => {
		let frame = doc.querySelector('iframe#chatframe');
		debug('frame:', frame);
		if (!frame) return;

		let btn = frame.contentWindow.document.querySelector('yt-live-chat-renderer #close-button button');
		debug('button:', btn);
		if (!btn) return;

		clearInterval(watcher);
		btn.dispatchEvent(new Event('click'));
		debug('done.');
	};

	doc.addEventListener('DOMContentLoaded', () => {
		update();
		watcher = setInterval(update, interval);
	});

})(document);