WhatsApp Web - Clean UI

Fix & debloat WhatsApp Web's interface

当前为 2025-07-02 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         WhatsApp Web - Clean UI
// @description  Fix & debloat WhatsApp Web's interface
// @author       Gamba
// @version      1.7
// @license      MIT
// @namespace    http://tampermonkey.net/
// @match        https://web.whatsapp.com/*
// @icon         https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://web.whatsapp.com/&size=256
// @grant        none
// @run-at       document-start
// ==/UserScript==

"use strict";

// Fix menu background exit
{
    window.addEventListener("keydown", onKeyboard, true);

    const exceptions =
    [
        "#app > div > span:nth-child(4) *",
        "#app > div > div > div > div:nth-child(3) > div:first-child > span > div > span > div > header > div > div:first-child > div",
        "#app > div > div > div > div:nth-child(3) > div:first-child > span > div > span > div > span > div > header > div > div:first-child > div",
        "#app > div > span:nth-child(3) > div"
    ];

    function onKeyboard(event)
    {
        if (event.key === "Escape")
        {
            const isException = exceptions.some(exception => event.target.matches(exception));
            const isValid = isChatsSelected() || isException;

            if (!isValid) event.stopImmediatePropagation();
        }
    }

    function isChatsSelected()
    {
        let chatsButton = document.querySelector("#app > div > div > div > header > div > div:first-child > div > div:first-child > button");

        return chatsButton.ariaPressed === "true";
    }
}

// Exit chat on change tab
{
    document.addEventListener("click", onClick, true);

    function onClick(event)
    {
        const button = event.target.closest("button");

        if (button)
        {
            const header = button.closest("header");

            if (header && header.parentElement.hasAttribute("tabindex"))
            {
                const keyEvent = new KeyboardEvent("keydown", { key: "Escape" });

                document.dispatchEvent(keyEvent);
            }
        }

        document.activeElement.blur();
    }
}

// Apply CSS
{
    const css =
    `
    /*Desktop app advertisement*/
    #app > div > div > div
    {
        > div:nth-child(5) > div:not(#main) > div
        {
            > div:nth-child(1),
            > div:nth-child(2)
            {
                display: none;
            }
        }

        > div:nth-child(3) > div:last-child > span
        {
            border: none;
            margin: 1px;

            > div[tabindex] > div:not([tabindex])
            {
                display: none;
            }
        }
    }

    #side > div:nth-child(5) *
    {
        display: none;
    }

    /*Channels & communities*/
    #app > div > div > div > header > div > div:first-child > div
    {
        > div:nth-child(3),
        > div:nth-child(4)
        {
            display: none;
        }
    }

    /*Video call button*/
    #main > header > div:last-child > div > div:first-child
    {
        display: none;
    }

    /*Chat lists*/
    #side > [role="tablist"]
    {
        display: none;
    }

    /*Chat dropdowns arrows*/
    #pane-side > div:nth-last-child(2) > div > div > div > div > div > div:not(:hover) > div:last-child > div:last-child > div:last-child > span:nth-child(3)
    {
        display: none;
    }

    /*Archived chats separator*/
    #app > div > div > div > div:nth-child(3) > div:first-child > span > div > span > div > div:last-child > div > div:nth-child(2) > div.xjm9jq1.xkh2ocl.x1uew315
    {
        display: none;
    }

    /*Popover tooltips*/
    #wa-popovers-bucket *
    {
        display: none;
    }

    /*Scrollbar*/
    *
    {
        scrollbar-width: unset !important;
        scrollbar-color: unset !important;
    }

    div
    {
        ::-webkit-scrollbar
        {
            width: 14px !important;
        }

        ::-webkit-scrollbar-button
        {
            display: none !important;
        }

        ::-webkit-scrollbar-track,
        ::-webkit-scrollbar-track-piece
        {
            background-color: transparent !important;
        }

        ::-webkit-scrollbar-thumb
        {
            height: 50px !important;

            border: 3px solid transparent !important;
            border-radius: 100px;
            background-clip: padding-box !important;

            background-color: rgba(var(--black-rgb), 20%) !important;
        }
    }

    .dark div ::-webkit-scrollbar-thumb
    {
        background-color: rgba(var(--white-rgb), 16%) !important;
    }
    `;

    const style = document.createElement("style");
    style.textContent = css;
    document.head.appendChild(style);
}