Telegram Web K(A) Post Enlarger

Increases minimum width of messages/posts in Telegram Web K and Telegram Web A

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 Web K(A) Post Enlarger
// @namespace    https://violentmonkey.github.io/
// @version      1.0
// @description  Increases minimum width of messages/posts in Telegram Web K and Telegram Web A
// @author       Streampunk
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAGI0lEQVR4nO1bW2xURRg+8q6A92eC9MwWKGJE4hW5vHhJeJBEJaSJiQnBFxPffKkS0whRLiaiJOKLIEHFIu7MbukFLakFuZZSWrrdtmzphZbednfmnO1efvOfugvt3s5t97TJfsmfNHtm5+z3zT//zPzzV5JKKKGEEkooPFb+EXqKMGWTzPgumfE9hIrDhPFjmlFxGD/DZ9gG20oLHlWwSKbKFpmKQ4TyDsIEGDGZ8ZuEim9REOxLWihYzoJPEMZ3y1T0GyWdVQzKA4Tyz1ecDj4uzVesck8uJVTskykP20U8gxBhwvhXFTUTS6R5A4CHZCYqZSruFop4+vQQw8QtdjhNXVrO4BGZ8RPFIp5BiBr0PEfIE0+onFDe4xT5+8b95W6VFJW8y8vXESZGnSef8oTxFVS8VBTyZW7xosw4d5p0mgiUh2XG1xfc7WUqxpwmm9WouOdiqqsg5CtqJpbMjzmf1xO6l9WNL7ZdAELFSafJ6RdB/GoreZmJS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PiQ03euF0a2+K/IH6a7DGE0q1efcfFUbV7HuCvrC1ACgzUSU5mRavvjAExy7NCHCgoXUW+aRtaFS0s34msEHzAdByWhyBNTlWBNhYF4QfznfD/vpWqGDp5JO2tlbAmeH0+YDH7aLs/nKVwRAqBq2I8EbtGKz2hPO2czEB3/mi2rxPYrvJHaDMxJBtt8TELXZYEcCo7boUgd/6Y9YSIB7xni3kkyCU/1xMEawYFm5JdmNZ3fhiLEhaAOS7cNpKhQD5U31mvlyVZ7HRFV5VlgoJmfH1hawGNT3yuFy7+QtSMVDO+POEipH5Q16MYfVaUcgngcWJWJDkOHnGu8o8apnkBMpOwcOE8uOOCUDF7/OicNrFxHbceBSR+KDt67wdyyQmUwtbUsODuL0t2DJnB/AAhWUpeAy1cZ7fxlOdyzv5qLRgUAWL8EYWixNkKm4Yc3GewO9gJkdLZiykf5nJBkxKuqiyEdPThPFqvHzBG6gZw4sYXo3PUDTDCcwSSiihhBIkU/gPl+NAtPTy4YcAAAAASUVORK5CYII=
// @match        https://web.telegram.org/k/*
// @match        https://web.telegram.org/a/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to inject or update custom styles
    function applyStyles() {
        // Remove previous style if exists
        const oldStyle = document.getElementById('tg-width-enlarger');
        if (oldStyle) {
            oldStyle.remove();
        }

        // Create new style element
        const style = document.createElement('style');
        style.id = 'tg-width-enlarger';
        style.textContent = `
            /* Main chat container */
            #RightColumn .messages-layout {
                min-width: 700px !important;
                max-width: none !important;
            }

            /* Message containers */
            .messages-layout .message,
            .message-bubble,
            .message-content,
            .bubble {
                min-width: 700px !important;
                width: auto !important;
                max-width: 100% !important;
                flex-shrink: 0 !important;
            }

            /* Inner content of messages */
            .message-inner,
            .text-content,
            .bubble-content,
            .webpage-message,
            .formatted-text {
                min-width: 650px !important;
                white-space: normal !important;
            }

            /* Channel posts and news items */
            .chat-list .message,
            .story-preview,
            .news-item,
            .channel-post {
                min-width: 700px !important;
            }

            /* Force minimum width on small screens */
            @media (max-width: 1300px) {
                #RightColumn {
                    min-width: 700px !important;
                }
                .middle-column {
                    min-width: 700px !important;
                }
            }
        `;
        document.head.appendChild(style);
    }

    // Apply styles immediately and on page load
    applyStyles();
    window.addEventListener('load', applyStyles);

    // Observe DOM changes for dynamically loaded messages
    const observer = new MutationObserver((mutations) => {
        let shouldUpdate = false;
        mutations.forEach((mutation) => {
            if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                shouldUpdate = true;
            }
        });
        if (shouldUpdate) {
            applyStyles();
        }
    });

    // Start observing the entire body
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

    // Reapply styles on window resize
    window.addEventListener('resize', applyStyles);

})();