Change Telegram web page elements

Move the Telegram chat bubble to the left and hide the "All Chats" button

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Change Telegram web page elements
// @namespace    https://greasyfork.org/zh-CN/users/737511
// @description  Move the Telegram chat bubble to the left and hide the "All Chats" button
// @version      0.4
// @icon         https://gcore.jsdelivr.net/gh/Bush2021/img-hosting@main/Icons/Telegram.svg
// @author       Bush2021
// @match        https://web.telegram.org/k/*
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const MENU_ITEM_SELECTOR = 'div.menu-horizontal-div-item';

    function moveChatElementsOnce() {
        GM_addStyle('.chat-input, .bubbles-date-group { transform: translateX(-95px); }');
    }

    function clickSecondElement() {
        const secondMenuItem = document.querySelector(`${MENU_ITEM_SELECTOR}:nth-of-type(2)`);
        if (secondMenuItem) {
            secondMenuItem.click();
        }
    }

    function hideAllChatsButton() {
        const allChatsButton = document.querySelector(MENU_ITEM_SELECTOR);
        if (allChatsButton && allChatsButton.textContent.trim().startsWith("All")) {
            allChatsButton.style.display = "none";
        }
    }

    function checkAndExecute() {
        const targetElement = document.querySelector(MENU_ITEM_SELECTOR);
        if (targetElement) {
            moveChatElementsOnce();
            clickSecondElement();
            hideAllChatsButton();
        } else {
            setTimeout(checkAndExecute, 10);
        }
    }

    checkAndExecute();
})();