API klici

This commit is contained in:
2026-04-20 14:43:50 +02:00
parent 737c7b92f3
commit a00028dbfa
6 changed files with 203 additions and 12 deletions

View File

@@ -0,0 +1,38 @@
function getLast() {
const url = `http://localhost:3000/vnosi`;
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: "*",
limit: 4
})
})
.then(response => response.json())
.then(data => {
if (!data.success) {
console.error('API Error:', data.message);
return;
}
for (let entry of data.data) {
let build = `
<div class="entry-card">
<h3 class="entry-title">${entry.kljuc}</h3>
<p class="entry-definition">${entry.tip}</p>
${entry.vsebina}
<p class="entry-example">${entry.primer}</p>
</div>
`;
document.getElementById("entry-container").innerHTML += build;
}
})
.catch((error) => {
console.error('Error:', error);
});
}
getLast();

View File

@@ -5,7 +5,7 @@ const headerHtml = `
<a class="nav-title" href="/">Slovar Slovenskega Novega Jezika</a>
</div>
<div class="nav-right" aria-label="Primary navigation">
<a class="nav-btn" href="/about.html">O nas</a>
<a class="nav-btn" href="/about.html">O projektu</a>
<a class="nav-btn" href="/contact.html">Kontakt</a>
<a class="nav-btn" href="/extras.html">Dodatki</a>
@@ -18,6 +18,12 @@ const headerHtml = `
</header>
`;
const footerHtml = `
<footer>
<p>&copy; ${new Date().getFullYear()} Jonas Korene Novak. Vse pravice pridržane.</p>
</footer>
`;
function getCurrentTheme() {
return document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light';
}
@@ -37,13 +43,17 @@ function updateToggleState(theme) {
document.addEventListener("DOMContentLoaded", function() {
// Naslov
document.title = ` ${document.title}`;
document.title = `SSNJ - ${document.title}`;
// Konstrukcija vseh stvari
for (let element of document.getElementsByClassName("page-header")) {
element.innerHTML = headerHtml;
}
for (let element of document.getElementsByClassName("page-footer")) {
element.innerHTML = footerHtml;
}
updateToggleState(getCurrentTheme());
});

View File

@@ -1,5 +1,9 @@
(function() {
const saved = localStorage.getItem('theme') || 'light';
const osPref = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', saved ?? osPref);
try {
const saved = localStorage.getItem('theme');
const osPref = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', saved || osPref);
} catch (e) {
document.documentElement.setAttribute('data-theme', 'light');
}
})();