WhatsApp Conversation Hider

Hides the conversation tab when ESC is pressed

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==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();
            }
        }
    });
})();