File size: 2,061 Bytes
4dfaeff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

var userLogged = false;
var usernameGotten = false;
var username = null;


function getUserInfo() {
    if (usernameGotten) {
        return;
    }
    userLogged = localStorage.getItem('userLogged');
    if (userLogged) {
        username = userInfoDiv.innerText;
        if (username) {
            if (username.includes("getting user info…")) {
                setTimeout(getUserInfo, 500);
                return;
            } else if (username === " ") {
                localStorage.removeItem("username");
                localStorage.removeItem("userLogged")
                userLogged = false;
                usernameGotten = true;
                return;
            } else {
                username = username.match(/User:\s*(.*)/)[1] || username;
                localStorage.setItem("username", username);
                usernameGotten = true;
                clearHistoryHtml();
            }
        }
    }
}

function showOrHideUserInfo() {
    function toggleUserInfoVisibility(shouldHide) {
        if (userInfoDiv) {
            if (shouldHide) {
                userInfoDiv.classList.add("info-transparent");
            } else {
                userInfoDiv.classList.remove("info-transparent");
            }
        }
    }

    // When webpage loaded, hide user info after 2 second
    setTimeout(function () {
        toggleUserInfoVisibility(true);
    }, 2000);

    let triggerElements = {appTitleDiv, userInfoDiv, sendBtn};
    for (let elem in triggerElements) {
        triggerElements[elem].addEventListener("mouseenter", function () {
            toggleUserInfoVisibility(false);
        });
        triggerElements[elem].addEventListener("mouseleave", function () {
            toggleUserInfoVisibility(true);
        });
        triggerElements[elem].ontouchstart = function () {
            toggleUserInfoVisibility(false);
        };
        triggerElements[elem].ontouchend = function () {
            setTimeout(function () {
                toggleUserInfoVisibility(true);
            }, 3000);
        };
    }
}