Whatsapp Sidebar Hider

Hide the whatsapp side bar

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @author      Carlos Feldmann <[email protected]>
// @namespace   https://feldmann.dev
// @name        Whatsapp Sidebar Hider
// @include     https://web.whatsapp.com/
// @version     0.2
// @description Hide the whatsapp side bar
// ==/UserScript==

(function () {
    let pane = null;
    let oldPane;
    let oldRegion;
    let region;
    let myButton = document.createElement("button");
    let hidding = false;

    function toggleVisibility() {
        pane = document.getElementById('pane-side');
        region = document.querySelector('[role="region"]');
        if (hidding) {
            pane.setAttribute('style', oldPane);
            region.setAttribute('style', oldRegion);
            myButton.innerHTML = 'Hide';
        } else {
            oldPane = pane.style.cssText;
            oldRegion = region.style.cssText;
            console.log(oldPane,oldRegion);
            pane.setAttribute('style', 'visibility:collapse !important');
            region.setAttribute('style', 'visibility:hidden !important');
            myButton.innerHTML = 'Show';
        }
        hidding = !hidding;
    }

    myButton.id = 'customButtom';
    myButton.innerHTML = "Hide";
    myButton.style.background = 'lightgray';
    myButton.style.color = 'black';
    myButton.style.borderRadius = '40px';
    myButton.style.padding = '5px';
    myButton.onclick = toggleVisibility;

    function changeButton() {
        let button = document.querySelector('[role="button"],[title="Status"]');
        let clone = button.parentNode.cloneNode(true);
        clone = button.parentNode.parentNode.insertBefore(clone, button.parentNode);
        clone.replaceChild(myButton, clone.firstChild);
    }


    function checkScreenLoaded() {
        setTimeout(function () {

            pane = document.getElementById('pane-side');
            region = document.querySelector('[role="region"]');
            if (pane != null && region != null) {
                changeButton();

            } else {
                checkScreenLoaded();
            }
        }, 50);
    }
    checkScreenLoaded();
})();