-
Notifications
You must be signed in to change notification settings - Fork 0
/
JS.js
52 lines (40 loc) · 1.36 KB
/
JS.js
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
const heightOffset = 25;
let direction = "ltr",
backgroundColor = "rgba(36, 6, 73, 0.15)",
messages = 0;
let contentElement;
window.addEventListener('onEventReceived', function (obj) {
if (!obj.detail.event) {
return;
}
if (typeof obj.detail.event.itemId !== "undefined") {
return;
}
const listener = obj.detail.listener.split("-")[0];
const event = obj.detail.event;
if (listener === 'message') {
renderText(event.renderedText, event.data);
} else if (listener === 'delete') {
addEvent('deleteMessage', event.data);
}
});
window.addEventListener('onWidgetLoad', function (obj) {
const fieldData = obj.detail.fieldData;
direction = fieldData.direction;
backgroundColor = fieldData.backgroundColor;
contentElement = document.getElementById('niconico-chat');
});
function renderText(text, data) {
let element = document.createElement('div');
element.classList.add("event-container");
element.style.top = `${heightOffset * messages}px`;
element.innerHTML = `<div data-msgId="${data.msgId}" data-userId="${data.userId}" id="${data.msgId}" class="msg-container">${text}</div>`;
contentElement.appendChild(element);
messages += 1;
window.setTimeout( () => {
messages = Math.max(0, (messages - 1))
}, 2000)
window.setTimeout( () => {
document.getElementById(data.msgId).parentElement.remove();
}, 6000 );
}