-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.js
70 lines (56 loc) · 2.43 KB
/
view.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// View.js
// The script for view.html
// Handles the display of saved chat logs
// Get all the keys from local storage
console.log("view script loaded");
chrome.storage.local.get(null, function (items) {
console.log("got items");
// For each key
// Create a div for the chat log list
var chatLogListDiv = document.createElement("div");
// Set the class to 'chat-log-list'
chatLogListDiv.className = "chat-log-list";
// Add the div to the document
document.body.appendChild(chatLogListDiv);
for (var key in items) {
// If the key ends with '-chatlog'
if (key.endsWith("-chatlog")) {
// Create a new div to hold the chat log list item
var chatLogListItemDiv = document.createElement("div");
// Set the class to 'chat-log-list-item'
chatLogListItemDiv.className = "chat-log-list-item";
// Create a new div to hold the chat log list item title
var chatLogListItemTitleDiv = document.createElement("div");
// Set the class to 'chat-log-list-item-title'
chatLogListItemTitleDiv.className = "chat-log-list-item-title";
// Set the inner text to the key
chatLogListItemTitleDiv.innerText = getDateStringFromKey(key);
// Add the div to the document
chatLogListItemDiv.appendChild(chatLogListItemTitleDiv);
// Get the chat log from the value
var chatLog = items[key];
// For each message in the chat log
chatLog.chatLog.forEach((message) => {
// Create a new div to hold the message
var newMessageDiv = document.createElement("div");
// Set the class to 'message-item'
newMessageDiv.className = "message-item";
// Set the innerHTML of the div to the message
newMessageDiv.innerText = message.text;
// Add the div to the document
chatLogListItemDiv.appendChild(newMessageDiv);
});
// Add the div to the document
chatLogListDiv.appendChild(chatLogListItemDiv);
}
}
});
// Split the key into the timestamp and the suffix
// convert the timestamp to a date and return
// the date as a string
function getDateStringFromKey(key) {
var splitKey = key.split("-");
var timestamp = splitKey[0];
var date = new Date(parseInt(timestamp));
return date.toString();
}