-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (56 loc) · 2.52 KB
/
Copy pathscript.js
File metadata and controls
65 lines (56 loc) · 2.52 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
document.getElementById("theme-toggle").addEventListener("click", function() {
document.body.classList.toggle("dark-mode");
this.textContent = document.body.classList.contains("dark-mode") ? "☀️ Light Mode" : "🌙 Dark Mode";
});
document.getElementById("poem-form").addEventListener("submit", function(event) {
event.preventDefault();
let author = document.getElementById("author").value;
let title = document.getElementById("title").value;
let content = document.getElementById("content").value;
let category = document.getElementById("category").value;
let poemDiv = document.createElement("div");
poemDiv.classList.add("poem");
poemDiv.setAttribute("data-category", category);
poemDiv.innerHTML = `
<h3>${title} - (${category})</h3>
<p>${content.replace(/\n/g, "<br>")}</p>
<p><strong>- ${author}</strong></p>
<div class="actions">
<button class="like-btn">❤️ Like <span>0</span></button>
<button class="comment-btn">💬 Comment</button>
<button class="share-btn">🔗 Share</button>
</div>
`;
document.getElementById("poem-list").appendChild(poemDiv);
document.getElementById("poem-form").reset();
addPoemEventListeners(poemDiv);
});
function addPoemEventListeners(poemDiv) {
let likeBtn = poemDiv.querySelector(".like-btn");
let likeCount = likeBtn.querySelector("span");
likeBtn.addEventListener("click", () => {
let count = parseInt(likeCount.textContent);
likeCount.textContent = count + 1;
});
let commentBtn = poemDiv.querySelector(".comment-btn");
commentBtn.addEventListener("click", () => {
let comment = prompt("अपनी टिप्पणी जोड़ें:");
if (comment) {
let commentPara = document.createElement("p");
commentPara.innerHTML = `💬 <strong>Comment:</strong> ${comment}`;
poemDiv.appendChild(commentPara);
}
});
let shareBtn = poemDiv.querySelector(".share-btn");
shareBtn.addEventListener("click", () => {
alert("आपकी कविता का लिंक कॉपी हो गया! 📋");
});
}
document.querySelectorAll(".category").forEach(button => {
button.addEventListener("click", () => {
let category = button.getAttribute("data-category");
document.querySelectorAll(".poem").forEach(poem => {
poem.style.display = poem.getAttribute("data-category") === category ? "block" : "none";
});
});
});