menjava domene

This commit is contained in:
2026-05-09 22:09:03 +02:00
parent e60826b8d9
commit 6e9efd2dbc
9 changed files with 178 additions and 12 deletions

View File

@@ -13,10 +13,39 @@
<main>
<h3 class="page-title">Dodatki</h3>
<hr>
<p class="page-paragraph">Ti dodatki so tukaj saj sem jih moral narediti za pogoje naloge. Nimajo praktične uporabe.</p>
<br>
<div class="page-btn-collection" style="margin-left: 20px;">
<button id="open-fin-modal" class="page-btn">Finančni kalkulator</button>
<button id="open-game-modal" class="page-btn">Igra</button>
</div>
<div class="modal" id="fin-modal">
<div class="modal-content">
<span class="close-fin-modal close">&times;</span>
<h2>Finančni kalkulator</h2>
<br>
<p>To je finančni kalkulator. Kliknite gumb spodaj, da ga zaprete.</p>
<div class="modal-buttons">
<button class="close-fin-modal page-btn">Zapri modal</button>
</div>
</div>
</div>
<div class="modal" id="game-modal">
<div class="modal-content">
<span class="close-game-modal close">&times;</span>
<h2>Igra</h2>
<br>
<p>To je igra. Kliknite gumb spodaj, da jo zaprete.</p>
<div class="modal-buttons">
<button class="close-game-modal page-btn">Zapri modal</button>
</div>
</div>
</div>
</main>
<div class="page-footer"></div>
<script src="./scripts/extras.js" defer></script>
<script src="./scripts/main.js" defer></script>
</body>
</html>

View File

@@ -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",

19
scripts/extras.js Normal file
View File

@@ -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";
});
});

View File

@@ -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: {

View File

@@ -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"

View File

@@ -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.";

View File

@@ -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",
`<div class="form-group"><p class="page-paragraph-error">${userMsg}</p></div>`
);
return;
}
const message = data.message || "Napaka pri registracijo! Preverite vnešene podatke oz. poskusite kasneje.";
form.insertAdjacentHTML(
"beforeend",
`<div class="form-group"><p class="page-paragraph-error">${message}</p></div>`

View File

@@ -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() {
<p class="entry-example">Vnos dodal: ${data.data.avtor}</p>
`;
// Voting UI: up, sum, down
const voteSum = Number(data.data.ocenaSuma) || 0;
const voteHtml = `
<div class="vote-controls" style="display:flex;align-items:center;gap:8px;margin-top:8px;">
<button id="vote-up" class="page-btn" aria-label="Upvote">▲</button>
<span id="vote-sum" style="min-width:36px;text-align:center;font-weight:600;">${voteSum}</span>
<button id="vote-down" class="page-btn" aria-label="Downvote">▼</button>
</div>
`;
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 = `<br><button id="delete-entry-button" class="page-btn nav-btn-danger">Izbriši vnos</button>`;
}
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();
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));
}
}

View File

@@ -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;