WhatsApp Hide Chat List

Hide WhatsApp Web chat list

目前為 2024-08-14 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
})();