diff --git a/ai-chat.js b/ai-chat.js new file mode 100644 index 0000000..a92e2d5 --- /dev/null +++ b/ai-chat.js @@ -0,0 +1,156 @@ +(() => { + const introMessage = + "Witaj, jestem twoim wirtualnym agentem Krzak.org, w czym mogę Ci pomóc?"; + const baseReplies = [ + "Niestety, nie umiem jeszcze tego zrobić", + "Nie jestem pewien o co Ci chodzi", + ]; + const offerFrom = [ + "pedałów", + "pajaca", + "noży", + "gwoździ", + "przypraw", + "słoika", + "słoików", + "tabletek", + "spreju", + "narzędzi", + "samolotu", + "osrtzałki", + "szafki", + "pojemnika", + "pojemników", + "ładowarki", + "ładowarek", + "wieszaków", + "wieszaka", + "półki", + "półek", + ]; + const offerTo = [ + "gwoździ", + "roweru", + "krojenia cebuli", + "pedałów", + "latania", + "łatania", + "podatków", + "sprzątania", + "wyrywania zębów", + "zmywarki", + "śmieci", + "krojenia chleba", + "krojenia ogórków", + "krojenia pomidorów", + "krojenia cebuli", + "krojenia ogórków", + "krojenia pomidorów", + "jedzenia", + "picia", + "kuchni", + "książek", + ]; + + const chatRoot = document.createElement("div"); + chatRoot.className = "ai-chat"; + chatRoot.innerHTML = ` + + + `; + document.body.appendChild(chatRoot); + + const fab = chatRoot.querySelector(".ai-chat__fab"); + const panel = chatRoot.querySelector(".ai-chat__panel"); + const closeBtn = chatRoot.querySelector(".ai-chat__close"); + const messages = chatRoot.querySelector(".ai-chat__messages"); + const form = chatRoot.querySelector(".ai-chat__form"); + const input = chatRoot.querySelector(".ai-chat__input"); + const backToTop = document.getElementById("back-to-top"); + + function addMessage(text, fromUser) { + const bubble = document.createElement("p"); + bubble.className = fromUser + ? "ai-chat__bubble ai-chat__bubble--user" + : "ai-chat__bubble"; + bubble.textContent = text; + messages.appendChild(bubble); + messages.scrollTop = messages.scrollHeight; + } + + function openChat() { + panel.classList.add("is-open"); + panel.setAttribute("aria-hidden", "false"); + fab.setAttribute("aria-expanded", "true"); + if (!messages.hasChildNodes()) { + addMessage(introMessage, false); + } + input.focus(); + } + + function closeChat() { + panel.classList.remove("is-open"); + panel.setAttribute("aria-hidden", "true"); + fab.setAttribute("aria-expanded", "false"); + } + + function randomItem(items) { + return items[Math.floor(Math.random() * items.length)]; + } + + function buildReply() { + return `${randomItem(baseReplies)}, ale mogę Ci zaoferować kupno ${randomItem(offerFrom)} do ${randomItem(offerTo)}.`; + } + + function syncChatPosition() { + if (!backToTop) { + chatRoot.classList.remove("ai-chat--raised"); + return; + } + chatRoot.classList.toggle( + "ai-chat--raised", + backToTop.classList.contains("visible"), + ); + } + + fab.addEventListener("click", () => { + if (panel.classList.contains("is-open")) { + closeChat(); + return; + } + openChat(); + }); + + closeBtn.addEventListener("click", closeChat); + + form.addEventListener("submit", (event) => { + event.preventDefault(); + const text = input.value.trim(); + if (!text) { + return; + } + addMessage(text, true); + addMessage(buildReply(), false); + input.value = ""; + }); + + if (backToTop) { + const observer = new MutationObserver(syncChatPosition); + observer.observe(backToTop, { + attributes: true, + attributeFilter: ["class"], + }); + window.addEventListener("resize", syncChatPosition); + } + syncChatPosition(); +})(); diff --git a/applications.html b/applications.html index 6e194d1..821b95a 100644 --- a/applications.html +++ b/applications.html @@ -197,5 +197,6 @@ + diff --git a/community/index.html b/community/index.html index d8296ed..aa59ca3 100644 --- a/community/index.html +++ b/community/index.html @@ -121,6 +121,7 @@ + diff --git a/contact.html b/contact.html index 180f82c..f5dd245 100644 --- a/contact.html +++ b/contact.html @@ -97,5 +97,6 @@ + diff --git a/dc.html b/dc.html index 24668f3..8ee4dc9 100644 --- a/dc.html +++ b/dc.html @@ -22,6 +22,7 @@

+ diff --git a/discord.html b/discord.html index d8296ed..425e085 100644 --- a/discord.html +++ b/discord.html @@ -85,7 +85,10 @@
  • - + Discord discord.gg/CY3Zr6baD7 @@ -121,6 +124,7 @@ + diff --git a/index.html b/index.html index 9f15b70..456bc68 100755 --- a/index.html +++ b/index.html @@ -167,23 +167,17 @@
  • - - Minecraft Server - Fabric 1.21.10 - -
  • -
  • Contact
  • -

    +

    If you want an account on any of these, want to suggest something new or get a subdomain, just message me

    -
    +
    Indexed by + diff --git a/mc.html b/mc.html index e24eacd..4135cec 100644 --- a/mc.html +++ b/mc.html @@ -504,6 +504,7 @@ +