Greasy Fork is available in English.

Collapse WhatsApp

Hide elements on WhatsApp Web using Alt+C (Channels) and Alt+S (Sidebar)

// ==UserScript==
// @name                Collapse WhatsApp
// @author              Rahatul Ghazi
// @description         Hide elements on WhatsApp Web using Alt+C (Channels) and Alt+S (Sidebar)
// @grant               none
// @homepage            https://github.com/rahaaatul/UserScripts
// @icon                data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAACXBIWXMAAAsTAAALEwEAmpwYAAAVlUlEQVR4nO3deVSTd7oH8NxZzsyd26ogCIqCoqC22pm517kztaed6Sw9d2plE0VARBEUl7q12ulM23E6trWrVq2sAgqyySIBQaSssiUkZCE7WUiAEBAR0FZrrd973kQUkbzvmxBA2zznfP/xtD09+fjm93ve531/YTDsZS972cte9rKXvexlL3vZy16jlqK3d4pS379M1dkfquzsf6NV33dIqb96rFXfl6Ts7MtWdPQltHZcOaLouPJ+a8eV1xT63lWy9r5ndDrdf47+X7QX7QLwHyrDtaVKQ98upb6/QKnv71R19YOIUn/1obR29j0URccVY+TtvXcU7b0aeUdvqkx3JbJV173ATkEXoXPweXVXf4La0N8zBDA8lmIMj7y99350l9vk7b0fSnV9S+04I0pluOai6ho4oOoaUKkNAyAyrhjDItNdhlR7WSDV9uzid3X91w8aR9XZ564y9H+uMgx8NQShnmCMB6Lt6ZVquw9IOjqmM35I1dExMF3dPRCjNvR/MxxiUjF0xJXSY0pbzzVpW89bCoXiZ4zv+xqh7h5Yr+ke6B4J8chgaO9HojEoJW09Kxjfx2rt7l+gNgzWaboH8VhgtHXfj8aQLdRqHRjfl9IYBv3VhsGrjyVGWzfEGgMRbUtb93LG41wKBX5GrBUEhC0wKtoUSFbW4qCsAFtFJxEkOAo//if4M/cgXuT+Gy9xD8Kn+SME8Y5gp/AU3pcwkaK4hLo29VgxjBGp9bdEKv1exuNYou7uJzSGwdKxYLR0GBCvrMY2cTJe4P0TS5teN4U9lNewhDWUvVjSuBdPD6Vhz708Vb8bL7I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WfVTbLI0jcqlZ+uklrvhftRzxvkvN4k01XPGfKhsFsxnftyJ+mJfX2v4iT65zm+z/F3vZy172spe97GUve9nLXozvQ/0/notDsIpLlXQAAAAASUVORK5CYII
// @license             MIT License
// @match               *://*.whatsapp.com/*
// @namespace           rahaaatul
// @source              https://github.com/rahaaatul/UserScripts/raw/refs/heads/main/Collapse%20Whatsapp/collapse-whatsapp.js
// @supportURL          https://github.com/rahaaatul/UserScripts/issues/new
// @version             1
// ==/UserScript==

(function () {
  "use strict";

  // Function to toggle Channel Lists
  function toggleChannels() {
    let elements = document.querySelectorAll(
      "._aigs.two > ._aigw._aigv, ._aigu > ._aohf._aigv._aigw._aigx"
    );

    elements.forEach((el) => {
      if (el.style.display === "none") {
        el.style.display = "flex";
      } else {
        el.style.display = "none";
      }
    });
  }

  // Function to toggle Sidebar
  function toggleSidebar() {
    let element = document.querySelector(
      "._aigs.two > .xn6708d.x1ye3gou.x1a0jr7w.xu3j5b3.xm81vs4.x1acz5yr.x5yr21d.xbyj736.xl56j7k.x6s0dn4.x78zum5.x9f619.x1n2onr6.xa1v5g2"
    );
    let targetElement = document.querySelector(
      "._aigu > ._aohf._aigv._aigw._aigx"
    );

    if (element.style.display === "none") {
      element.style.display = "flex";
      targetElement.style.marginInlineStart = "var(--navbar-width)";
    } else {
      element.style.display = "none";
      targetElement.style.marginInlineStart = "unset";
    }
  }

  // Event listener to toggle functions
  document.addEventListener("keydown", function (e) {
    if (e.altKey && e.key.toLowerCase() === "c") {
      e.preventDefault();
      toggleChannels();
    } else if (e.altKey && e.key.toLowerCase() === "s") {
      e.preventDefault();
      toggleSidebar();
    }
  });
})();