-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.html
More file actions
80 lines (72 loc) · 2.92 KB
/
comment.html
File metadata and controls
80 lines (72 loc) · 2.92 KB
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
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Comments - Artisan Echoes</title>
<style>
body { font-family: Arial, sans-serif; background: #fafafa; margin: 0; padding: 0; }
.container { max-width: 600px; margin: 40px auto; background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
h2 { margin-bottom: 20px; }
.comment-box { display: flex; gap: 10px; }
.comment-box input { flex: 1; padding: 10px; border: 1px solid #ccc; border-radius: 5px; }
.comment-box button { padding: 10px 15px; background: #FD7B6B; border: none; color: #fff; border-radius: 5px; cursor: pointer; }
.comment-box button:hover { background: #e56755; }
.comment-list { margin-top: 20px; }
.comment { display: flex; justify-content: space-between; align-items: center; background: #f5f5f5; padding: 10px; border-radius: 5px; margin-bottom: 10px; }
.comment span { font-size: 16px; }
.delete-btn { background: none; border: none; color: red; font-size: 14px; cursor: pointer; }
</style>
</head>
<body>
<div class="container">
<h2>Comments</h2>
<div class="comment-box">
<input type="text" id="commentInput" placeholder="Write a comment...">
<button id="postCommentBtn">Post</button>
</div>
<div class="comment-list" id="commentList"></div>
<button onclick="window.location.href='index.html'" style="margin-top:20px;">⬅ Back</button>
</div>
<script>
const params = new URLSearchParams(window.location.search);
const postId = params.get("postId");
const commentInput = document.getElementById("commentInput");
const postBtn = document.getElementById("postCommentBtn");
const commentList = document.getElementById("commentList");
// Load saved comments
let comments = JSON.parse(localStorage.getItem(`post_${postId}_comments`)) || [];
function renderComments() {
commentList.innerHTML = "";
comments.forEach((comment, index) => {
const div = document.createElement("div");
div.className = "comment";
div.innerHTML = `
<span>${comment}</span>
<button class="delete-btn" onclick="deleteComment(${index})">❌ Delete</button>
`;
commentList.appendChild(div);
});
}
function saveComments() {
localStorage.setItem(`post_${postId}_comments`, JSON.stringify(comments));
localStorage.setItem(`post_${postId}_commentCount`, comments.length);
}
postBtn.addEventListener("click", () => {
const text = commentInput.value.trim();
if (!text) return;
comments.push(text);
saveComments();
renderComments();
commentInput.value = "";
});
function deleteComment(index) {
comments.splice(index, 1);
saveComments();
renderComments();
}
// Initial render
renderComments();
</script>
</body>
</html>