WhatsApp Hide Chat List

Hide WhatsApp Web chat list

当前为 2024-08-14 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        WhatsApp Hide Chat List
// @namespace   Violentmonkey Scripts
// @version     0.3
// @grant       none
// @license     GNU GPLv3
// @author      imxitiz
// @match       https://web.whatsapp.com/
// @description Hide WhatsApp Web chat list
// ==/UserScript==

(function () {
    'use strict';

    let hasInitialized = false;
    const hideThreshold = 60;
    let eventParent;

    // Update chat list visibility
    function updateChatListVisibility() {
        const chatList = document.querySelector("div._aigv:nth-child(4)");
        const headerElement = document.querySelector(".xbyj736");

        if (chatList) {
            if (!hasInitialized) {
                chatList.style.display = "flex";
                chatList.style.flex = "0 0";
                chatList.style.maxWidth = "90%";
                chatList.style.width = "0%";
                chatList.style.transition = "width .5s ease-out 0s";

                // headerElement.style.paddingLeft = '0px';
                // headerElement.style.transition = 'all .5s ease-out 0s';

                hasInitialized = true;
            }
            const isMouseOverElement = isMouseOver(chatList);

            if (isMouseOverElement || eventParent.clientX <= hideThreshold) {
                // Show
                chatList.style.width = "100%";
                // headerElement.style.paddingLeft = '16px';
            } else {
                // Hide
                chatList.style.width = "0%";
                // headerElement.style.paddingLeft = '0px';
            }
        }
    }

    // Check if mouse is over the element or its children
    function isMouseOver(element) {
        return element.contains(eventParent.target);
    }

    // Set up MutationObserver
    const observer = new MutationObserver(function (mutations) {
        mutations.forEach(function (mutation) {
            if (mutation.type === "childList") {
                // If there are added nodes, update the element visibility
                if (mutation.addedNodes.length > 0) {
                    updateChatListVisibility();
                }
            }
        });
    });

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

    // Initialize the script
    function init() {
        document.addEventListener("mousemove", function (event) {
            eventParent = event;
            updateChatListVisibility(event);
        });
        document.addEventListener("mouseleave", updateChatListVisibility);
    }

    init();
})();