File size: 2,147 Bytes
4dfaeff
0cc999a
4dfaeff
0cc999a
4dfaeff
 
 
 
 
 
 
0cc999a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4dfaeff
 
0cc999a
4dfaeff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0cc999a
 
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
69
70
71

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


function getUserInfo() {
    if (usernameGotten) {
        return;
    }
    // userLogged = localStorage.getItem('userLogged');
    // if (userLogged) {
    usernameTmp = userInfoDiv.innerText;
    if (usernameTmp) {
        if (usernameTmp.includes("getting user info")) {
            setTimeout(getUserInfo, 500);
            return;
        } else if (usernameTmp === " ") {
            localStorage.removeItem("username");
            // localStorage.removeItem("userLogged")
            // userLogged = false;
            usernameGotten = true;
            return;
        } else {
            usernameTmp = usernameTmp.match(/User:\s*(.*)/)[1] || usernameTmp;
            localStorage.setItem("username", usernameTmp);
            username = usernameTmp;
            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};
    let triggerElements = {userInfoDiv, statusDisplay};
    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);
        };
    }
}