From 6e9efd2dbc62fb1ae3e0ba467823557e27818828 Mon Sep 17 00:00:00 2001 From: DcruBro Date: Sat, 9 May 2026 22:09:03 +0200 Subject: [PATCH] menjava domene --- extras.html | 29 +++++++++++++ scripts/contact.js | 2 +- scripts/extras.js | 19 ++++++++ scripts/index.js | 4 +- scripts/login.js | 2 +- scripts/new.js | 2 +- scripts/register.js | 24 ++++++++++- scripts/vnos.js | 103 +++++++++++++++++++++++++++++++++++++++++--- styles/main.css | 5 +++ 9 files changed, 178 insertions(+), 12 deletions(-) create mode 100644 scripts/extras.js diff --git a/extras.html b/extras.html index df63686..bbbbf3b 100644 --- a/extras.html +++ b/extras.html @@ -13,10 +13,39 @@

Dodatki


+

Ti dodatki so tukaj saj sem jih moral narediti za pogoje naloge. Nimajo praktične uporabe.

+
+
+ + +
+ +
+ \ No newline at end of file diff --git a/scripts/contact.js b/scripts/contact.js index 6091fda..456a146 100644 --- a/scripts/contact.js +++ b/scripts/contact.js @@ -16,7 +16,7 @@ document.addEventListener("DOMContentLoaded", () => { document.getElementById("contact-form").addEventListener("submit", (e) => { e.preventDefault(); - const url = "http://localhost:3000/kontakt"; + const url = "https://ssnj.dcrubro.com/api/kontakt"; const message = document.getElementById("message").value; fetch(url, { method: "POST", diff --git a/scripts/extras.js b/scripts/extras.js new file mode 100644 index 0000000..a0bd268 --- /dev/null +++ b/scripts/extras.js @@ -0,0 +1,19 @@ +document.getElementById("open-fin-modal").addEventListener("click", function() { + document.getElementById("fin-modal").style.visibility = "visible"; +}); + +document.querySelectorAll(".close-fin-modal").forEach(function(button) { + button.addEventListener("click", function() { + document.getElementById("fin-modal").style.visibility = "hidden"; + }); +}); + +document.getElementById("open-game-modal").addEventListener("click", function() { + document.getElementById("game-modal").style.visibility = "visible"; +}); + +document.querySelectorAll(".close-game-modal").forEach(function(button) { + button.addEventListener("click", function() { + document.getElementById("game-modal").style.visibility = "hidden"; + }); +}); \ No newline at end of file diff --git a/scripts/index.js b/scripts/index.js index ba2745d..5c1dde9 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -3,7 +3,7 @@ function getSpecific(kljuc) { } function getLast() { - const url = `http://localhost:3000/vnosi`; + const url = `https://ssnj.dcrubro.com/api/vnosi`; fetch(url, { method: 'POST', headers: { @@ -44,7 +44,7 @@ function search() { const val = field.value; if (!val || val === "" || val === "*") { return; } - const url = `http://localhost:3000/vnosi`; + const url = `https://ssnj.dcrubro.com/api/vnosi`; fetch(url, { method: 'POST', headers: { diff --git a/scripts/login.js b/scripts/login.js index 092a8ab..9ef6eb2 100644 --- a/scripts/login.js +++ b/scripts/login.js @@ -16,7 +16,7 @@ document.getElementById("login-form").addEventListener("submit", async function( const form = document.getElementById("login-form"); try { - const response = await fetch("http://localhost:3000/prijava", { + const response = await fetch("https://ssnj.dcrubro.com/api/prijava", { method: "POST", headers: { "Content-Type": "application/json" diff --git a/scripts/new.js b/scripts/new.js index 73f40d0..9a4140d 100644 --- a/scripts/new.js +++ b/scripts/new.js @@ -35,7 +35,7 @@ const form = ` document.getElementById("confirm-add").addEventListener("click", () => { document.getElementById("new-entry-form-modal").style.display = "none"; - const url = "http://localhost:3000/nov-vnos"; + const url = "https://ssnj.dcrubro.com/api/nov-vnos"; let content = document.getElementById("content").value; const key = document.getElementById("key").value; const examples = document.getElementById("examples").value ? "Primer: " + document.getElementById("examples").value : "Ni podanih primerov."; diff --git a/scripts/register.js b/scripts/register.js index ce4a3fc..5255b58 100644 --- a/scripts/register.js +++ b/scripts/register.js @@ -46,7 +46,7 @@ document.getElementById("login-form").addEventListener("submit", async function( return; } - const response = await fetch("http://localhost:3000/registracija", { + const response = await fetch("https://ssnj.dcrubro.com/api/registracija", { method: "POST", headers: { "Content-Type": "application/json" @@ -67,7 +67,27 @@ document.getElementById("login-form").addEventListener("submit", async function( return; } - const message = data.message || "Napaka pri registraciji! Preverite vnešene podatke oz. poskusite kasneje."; + if (response.status === 409) { + // Prefer the server-provided message when available; otherwise map known conflict types to Slovenian text + const serverMsg = (data && data.message) ? String(data.message).toLowerCase() : ""; + let userMsg = "Uporabniško ime ali e-pošta je že zasedena."; + + if (serverMsg.includes('username') || serverMsg.includes('uporab') || serverMsg.includes('user')) { + userMsg = 'Uporabniško ime je že zasedeno.'; + } else if (serverMsg.includes('email') || serverMsg.includes('e-pošta') || serverMsg.includes('e-naslov')) { + userMsg = 'E-poštni naslov je že uporabljen.'; + } else if (serverMsg) { + userMsg = data.message; // show server message if it's something specific + } + + form.insertAdjacentHTML( + "beforeend", + `

${userMsg}

` + ); + return; + } + + const message = data.message || "Napaka pri registracijo! Preverite vnešene podatke oz. poskusite kasneje."; form.insertAdjacentHTML( "beforeend", `

${message}

` diff --git a/scripts/vnos.js b/scripts/vnos.js index 58d81ed..9075a0b 100644 --- a/scripts/vnos.js +++ b/scripts/vnos.js @@ -1,7 +1,12 @@ const kljuc = new URLSearchParams(window.location.search).get("kljuc"); +function getCookie(name) { + const match = document.cookie.split(";").map(c => c.trim()).find(c => c.startsWith(name + "=")); + return match ? match.split("=")[1] : null; +} + function getKey() { - const url = `http://localhost:3000/vnos`; + const url = `https://ssnj.dcrubro.com/api/vnos`; fetch(url, { method: 'POST', headers: { @@ -26,17 +31,33 @@ function getKey() {

Vnos dodal: ${data.data.avtor}

`; + // Voting UI: up, sum, down + const voteSum = Number(data.data.ocenaSuma) || 0; + const voteHtml = ` +
+ + ${voteSum} + +
+ `; + + build += voteHtml; + // Preveri lastinino let addIf = ``; - if (data.data.avtor === document.cookie.split(";").find(cookie => cookie.trim().startsWith("username="))?.split("=")[1]) { + if (data.data.avtor === getCookie("username")) { addIf = `
`; } build += addIf; document.getElementById("page-title").innerText = `Vnos '${data.data.kljuc}'`; - document.getElementById("entry-container-single").innerHTML += build; + // replace contents (avoid appending duplicates) + document.getElementById("entry-container-single").innerHTML = build; + + // Initialize vote state after rendering + initVoting(data.data); document.getElementById("delete-entry-button")?.addEventListener("click", () => { document.getElementById("delete-entry-modal").style.visibility = "visible"; @@ -47,7 +68,7 @@ function getKey() { }); document.getElementById("confirm-delete")?.addEventListener("click", () => { - fetch("http://localhost:3000/izbrisi-vnos", { + fetch("https://ssnj.dcrubro.com/api/izbrisi-vnos", { method: "POST", headers: { "Content-Type": "application/json" @@ -79,4 +100,76 @@ function getKey() { }); } -getKey(); \ No newline at end of file +getKey(); + +function initVoting(entryData) { + const upBtn = document.getElementById('vote-up'); + const downBtn = document.getElementById('vote-down'); + const sumEl = document.getElementById('vote-sum'); + if (!upBtn || !downBtn || !sumEl) return; + + const token = getCookie('token'); + + let currentVote = 0; + + function setActive(v) { + upBtn.classList.toggle('nav-btn-primary', v === 1); + downBtn.classList.toggle('nav-btn-primary', v === -1); + currentVote = v; + } + + if (!token) { + const showLogin = () => alert('Prijavite se, da lahko glasujete.'); + upBtn.addEventListener('click', showLogin); + downBtn.addEventListener('click', showLogin); + return; + } + + // fetch whether the current user has voted + fetch('https://ssnj.dcrubro.com/api/semvolil', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ token: token, pk: kljuc }) + }) + .then(r => r.json()) + .then(obj => { + const v = obj?.vote || 0; + setActive(v); + }) + .catch(err => console.error('semvolil error', err)); + + upBtn.addEventListener('click', () => submitVote(1)); + downBtn.addEventListener('click', () => submitVote(-1)); + + function submitVote(vote) { + const tokenNow = getCookie('token'); + if (!tokenNow) { alert('Prijavite se, da lahko glasujete.'); return; } + + // if user clicks the same vote, send 0 to remove it + const sendVote = (vote === currentVote) ? 0 : vote; + + fetch('https://ssnj.dcrubro.com/api/volI', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ token: tokenNow, pk: kljuc, vote: sendVote }) + }) + .then(r => r.json()) + .then(() => { + // refresh current score + return fetch('https://ssnj.dcrubro.com/api/vnos', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ pk: kljuc }) + }); + }) + .then(r => r.json()) + .then(d => { + if (d.success) { + const newSum = Number(d.data.ocenaSuma) || 0; + sumEl.innerText = newSum; + setActive(sendVote); + } + }) + .catch(err => console.error('vote error', err)); + } +} \ No newline at end of file diff --git a/styles/main.css b/styles/main.css index 8444653..c3750f2 100644 --- a/styles/main.css +++ b/styles/main.css @@ -375,6 +375,11 @@ nav { color: var(--nav-btn-primary-bg); } +.page-btn-collection { + display: flex; + gap: 10px; +} + .modal-content { background: var(--nav-btn-bg); padding: 20px;