From 883208f7df0d3c419027e2ec3e69829e314e99b1 Mon Sep 17 00:00:00 2001 From: Origami Date: Tue, 14 Oct 2025 00:32:10 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=94=D0=97:=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=B5=D0=B2=20=E2=80=94=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE?= =?UTF-8?q?=D0=BD,=20=D0=B4=D0=B0=D1=82=D0=B0,=200=20=D0=BB=D0=B0=D0=B9?= =?UTF-8?q?=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 6f14ae14aa..64ddfeb8ea 100644 --- a/index.html +++ b/index.html @@ -48,16 +48,18 @@
- +
@@ -66,6 +68,45 @@ From dfa72853562f89e9bf130f1ef51988cfd2442634 Mon Sep 17 00:00:00 2001 From: Origami Date: Tue, 14 Oct 2025 19:08:27 +0300 Subject: [PATCH 2/5] correction --- index.html | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 64ddfeb8ea..de30591604 100644 --- a/index.html +++ b/index.html @@ -72,15 +72,20 @@ const addComment = document.getElementById("comment"); const buttonAdd = document.getElementById("button"); const commentsList = document.querySelector(".comments"); - const currentTime = new Date().toLocaleString(); - addName.addEventListener("input", () => {}); - addComment.addEventListener("input", () => {}); buttonAdd.addEventListener("click", () => { - const currentTime = new Date().toLocaleString(); + const now = new Date(); + const currentTime = now.toLocaleString("ru-RU", { + day: "2-digit", + month: "2-digit", + year: "2-digit", + hour: "2-digit", + minute: "2-digit", + }); const nameValue = addName.value; const commentValue = addComment.value; if (nameValue === "" || commentValue === "") { + alert("Напиши что нибудь!"); return; } From 68093c04e3e4d4c5898de88a35a20a819a0c7587 Mon Sep 17 00:00:00 2001 From: Origami Date: Tue, 14 Oct 2025 19:15:27 +0300 Subject: [PATCH 3/5] correction time --- index.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index de30591604..1910f24b77 100644 --- a/index.html +++ b/index.html @@ -75,13 +75,18 @@ buttonAdd.addEventListener("click", () => { const now = new Date(); - const currentTime = now.toLocaleString("ru-RU", { + const dateStr = now.toLocaleDateString("ru-RU", { day: "2-digit", month: "2-digit", year: "2-digit", + }); + const timeStr = now.toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit", + hour12: false, }); + + const currentTime = `${dateStr} ${timeStr}`; const nameValue = addName.value; const commentValue = addComment.value; if (nameValue === "" || commentValue === "") { From a5ccd4c3e9863f5dc8f68f2b303947ad9a027280 Mon Sep 17 00:00:00 2001 From: Origami Date: Wed, 15 Oct 2025 01:02:04 +0300 Subject: [PATCH 4/5] HW_2 --- index.html | 127 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 55 deletions(-) diff --git a/index.html b/index.html index 1910f24b77..1495d4d48e 100644 --- a/index.html +++ b/index.html @@ -8,42 +8,7 @@
-
    -
  • -
    -
    Глеб Фокин
    -
    12.02.22 12:18
    -
    -
    -
    - Это будет первый комментарий на этой странице -
    -
    - -
  • -
  • -
    -
    Варвара Н.
    -
    13.02.22 19:22
    -
    -
    -
    - Мне нравится как оформлена эта страница! ❤ -
    -
    - -
  • -
+
    { + const items = comments.map( + (item, index) => ` +
  • +
    +
    ${item.name}
    +
    ${item.date}
    +
    +
    +
    ${item.text}
    +
    + +
  • + ` + ); + const html = items.join(""); + commentsList.innerHTML = html; + }; + + renderComments(); + buttonAdd.addEventListener("click", () => { const now = new Date(); const dateStr = now.toLocaleDateString("ru-RU", { @@ -94,29 +105,35 @@ return; } - const newComment = `
  • -
    -
    ${nameValue}
    -
    ${currentTime}
    -
    -
    -
    - ${commentValue} -
    -
    - -
  • - `; - commentsList.innerHTML += newComment; + comments.push({ + name: nameValue, + text: commentValue, + date: currentTime, + likes: 0, + isLiked: false, + }); + + renderComments(); addName.value = ""; addComment.value = ""; }); + commentsList.addEventListener("click", (e) => { + const likeBtn = e.target.closest(".like-button"); + if (!likeBtn) return; + const i = Number(likeBtn.dataset.index); + if (Number.isNaN(i)) return; + + if (!comments[i].isLiked) { + comments[i].isLiked = true; + comments[i].likes += 1; + } else { + comments[i].isLiked = false; + comments[i].likes -= 1; + } + renderComments(); + }); + console.log("It works!"); From 988c7f5387726cea876abf240ced69c424667330 Mon Sep 17 00:00:00 2001 From: Origami Date: Wed, 22 Oct 2025 04:15:12 +0300 Subject: [PATCH 5/5] 1 --- index.html | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 1495d4d48e..fb1fcaf9cc 100644 --- a/index.html +++ b/index.html @@ -98,8 +98,16 @@ }); const currentTime = `${dateStr} ${timeStr}`; - const nameValue = addName.value; - const commentValue = addComment.value; + const nameValue = addName.value + .replaceAll("&", "&") + .replaceAll("<", "<") + .replaceAll(">", ">") + .trim(); + const commentValue = addComment.value + .replaceAll("&", "&") + .replaceAll("<", "<") + .replaceAll(">", ">") + .trim(); if (nameValue === "" || commentValue === "") { alert("Напиши что нибудь!"); return; @@ -134,6 +142,26 @@ renderComments(); }); + commentsList.addEventListener("click", (e) => { + const item = e.target.closest(".comment"); + if (!item || !commentsList.contains(item)) return; + + const author = + item + .querySelector(".comment-header > div:first-child") + ?.textContent.trim() ?? ""; + const text = + item.querySelector(".comment-text")?.textContent.trim() ?? ""; + + const quote = `@${author}: "${text}" `; + addComment.value = quote; + addComment.focus(); + addComment.setSelectionRange( + addComment.value.length, + addComment.value.length + ); + }); + console.log("It works!");