forked from Abhay-N-J/NotO
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patht.js
55 lines (52 loc) · 1.5 KB
/
t.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
var id = window.location.search.slice(1);
var thread = threads.find(t => t.id == id);
var header = document.querySelector('.header');
var headerHtml = `
<h4 class="title">
${thread.title}
</h4>
<div class="bottom">
<p class="timestamp">
${new Date(thread.date).toLocaleString()}
</p>
<p class="comment-count">
${thread.comments.length} comments
</p>
</div>
`
header.insertAdjacentHTML('beforeend', headerHtml)
function addComment(comment) {
var commentHtml = `
<div class="comment">
<div class="top-comment">
<p class="user">
${comment.author}
</p>
<p class="comment-ts">
${new Date(comment.date).toLocaleString()}
</p>
</div>
<div class="comment-content">
${comment.content}
</div>
</div>
`
comments.insertAdjacentHTML('beforeend', commentHtml);
}
var comments = document.querySelector('.comments');
for (let comment of thread.comments) {
addComment(comment);
}
var btn = document.querySelector('button');
btn.addEventListener('click', function() {
var txt = document.querySelector('textarea');
var comment = {
content: txt.value,
date: Date.now(),
author: 'Aaron'
}
addComment(comment);
txt.value = '';
thread.comments.push(comment);
localStorage.setItem('threads', JSON.stringify(threads));
})