Toggle WhatsApp Sidebar Width

Changes Whatsapp Web, contact size so it can be toggled on or off.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @license Public
// @name         Toggle WhatsApp Sidebar Width
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Changes Whatsapp Web, contact size so it can be toggled on or off.
// @author       Atos
// @match        *://web.whatsapp.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Función para añadir el botón de toggle
    function addToggleButton() {
        // Crear el botón
        var toggleButton = document.createElement('button');
        toggleButton.style.position = 'fixed';
        toggleButton.style.top = '10px';
        toggleButton.style.left = '10px';
        toggleButton.style.zIndex = '9999';
        toggleButton.style.width = '40px';
        toggleButton.style.height = '40px';
        toggleButton.style.borderRadius = '50%';
        toggleButton.style.backgroundColor = '#25D366'; // Color de WhatsApp
        toggleButton.style.border = 'none';
        toggleButton.style.cursor = 'pointer';
        toggleButton.style.display = 'flex';
        toggleButton.style.alignItems = 'center';
        toggleButton.style.justifyContent = 'center';

        // Crear el contenedor de las líneas
        var lineContainer = document.createElement('div');
        lineContainer.style.width = '20px';
        lineContainer.style.height = '20px';
        lineContainer.style.display = 'flex';
        lineContainer.style.flexDirection = 'column';
        lineContainer.style.justifyContent = 'space-around';

        // Crear las líneas
        for (var i = 0; i < 3; i++) {
            var line = document.createElement('div');
            line.style.width = '100%';
            line.style.height = '2px';
            line.style.backgroundColor = 'white';
            lineContainer.appendChild(line);
        }

        // Añadir el contenedor de líneas al botón
        toggleButton.appendChild(lineContainer);

        // Añadir el botón al body
        document.body.appendChild(toggleButton);

        // Establecer el estado inicial del botón
        toggleButton.setAttribute('data-state', 'open');

        // Añadir evento de click para cambiar el CSS
        toggleButton.addEventListener('click', function() {
            var style = document.createElement('style');
            style.type = 'text/css';

            if (toggleButton.getAttribute('data-state') === 'open') {
                style.innerHTML = `
                    @media screen {
                        .two ._aigw {
                            flex: 0 0 10% !important;
                            max-width: 10% !important;
                        }
                    }
                `;
                toggleButton.setAttribute('data-state', 'closed');
            } else {
                style.innerHTML = `
                    @media screen {
                        .two ._aigw {
                            flex: 0 0 40% !important;
                            max-width: 40% !important;
                        }
                    }
                `;
                toggleButton.setAttribute('data-state', 'open');
            }

            // Añadir el estilo al head del documento
            document.head.appendChild(style);
        });
    }

    // Esperar a que la página se cargue completamente
    window.addEventListener('load', function() {
        // Intenta añadir el botón cada segundo hasta que se encuentre el elemento
        var interval = setInterval(function() {
            addToggleButton();
            clearInterval(interval);
        }, 1000);

        // Detiene el intervalo después de 10 segundos
        setTimeout(function() {
            clearInterval(interval);
        }, 10000);
    });
})();