WhatsApp Conversation Hider

Hides the conversation tab when ESC is pressed

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         WhatsApp Conversation Hider
// @namespace    https://roinujnosde.me
// @version      0.3
// @description  Hides the conversation tab when ESC is pressed
// @author       RoinujNosde
// @match        https://web.whatsapp.com/
// @icon         https://web.whatsapp.com/favicon.ico
// @grant        none
// @run-at       document-idle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    var closeConvoClassName = "_2oldI dJxPU";

    function isConversationOpen() {
        return document.getElementsByClassName("_3xTHG").length > 0;
    }

    function hideOptions() {
        document.getElementsByClassName("o--vV wGJyi")[0].style.display = "none";
    }

    function getMoreOptions() {
        return document.getElementsByClassName("_26lC3")[4];
    }

    function closeConversation() {
        if (!isConversationOpen()) {
            return;
        }
        getMoreOptions().click();
        setTimeout(function() {
            var buttons = document.getElementsByClassName(closeConvoClassName);
            if (buttons.length === 6) { //it's a group
                document.getElementsByClassName("_3K4-L")[0].focus(); //scroll works again
                hideOptions();
                return;
            }
            var index = buttons.length === 9 ? 4 : 2;
            buttons[index].click()
            hideOptions();
        }, 1);
    }

    document.addEventListener('keydown', function(event) {
        if (event.key === "Escape") {
            console.debug("Esc pressed");
            if (closeConversation()) {
                event.preventDefault();
            }
        }
    });
})();