Telegram | Fix fullscreen without custom controls

fix fullscreen mode for videos without custom controls

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            Telegram | Fix fullscreen without custom controls
// @namespace       https://greasyfork.org/users/821661
// @version         1.1
// @description     fix fullscreen mode for videos without custom controls
// @author          hdyzen
// @match           https://web.telegram.org/a/*
// @grant           none
// @license         GPL-3.0-only
// ==/UserScript==

const stl = `
    .VideoPlayer:fullscreen video { 
        max-height: unset !important; 
    } 
    .VideoPlayer:fullscreen > :first-child { 
        width: 100% !important; 
        height: 100% !important; 
    }
`;

document.addEventListener("mousedown", async (ev) => {
    const fullscreen = ev.target.closest(".Button.fullscreen");
    if (!fullscreen) return;

    ev.stopImmediatePropagation();

    if (document.fullscreenElement) {
        document.exitFullscreen();
        return;
    }

    const player = document.querySelector(".MediaViewerSlide--active .VideoPlayer");
    if (!player) return;

    await player.requestFullscreen();

    const video = player.querySelector("video");
    setTimeout(() => video.removeAttribute("controls"), 100);
});

document.head.insertAdjacentHTML("beforeend", `<style>${stl}</style>`);