summaryrefslogtreecommitdiff
path: root/scripts/gui-common/log.js
blob: e5f2bbfe47ad2b0d895f02abb294fb456b110dac (plain)
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
'use strict';


const LOG_EL = document.getElementsByTagName("log")[0];
let LAST_LOG_TYPE = "";

function at_bot(el) {
    return el.scrollTop >= (el.scrollHeight - el.clientHeight)
}

function addLogEntry(object) {

    let do_scroll = at_bot(LOG_EL);

    let out = {
        type: object.type,
        target: object.target
    };

    if (LAST_LOG_TYPE == "mousemove" || LAST_LOG_TYPE == "touchmove") {
        if (LAST_LOG_TYPE == out.type)
            return;
    }

    LAST_LOG_TYPE = out.type;

    let entry = document.createElement("entry");
    entry.innerText = JSON.stringify(out);

    LOG_EL.appendChild(entry);

    if (do_scroll) {
        LOG_EL.scroll({
            top: LOG_EL.scrollHeight,
            behavior: "instant",
        });
    }
}