function getSpecific(kljuc) {
window.open(new URL(`vnos.html?kljuc=${kljuc}`, window.location.href).href, "_top");
}
function getLast() {
const url = `https://ssnj.dcrubro.com/api/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 = `
${entry.kljuc}
${entry.tip}
${entry.vsebina}
${entry.primer}
`;
document.getElementById("entry-container").innerHTML += build;
}
})
.catch((error) => {
console.error("Error:", error);
});
}
function search() {
const field = document.getElementById("search-input");
const val = field.value;
if (!val || val === "" || val === "*") { return; }
const url = `https://ssnj.dcrubro.com/api/vnosi`;
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
query: `*${val}*`, // Potencialno mora biti tukaj en "*" wildcard
limit: -1,
sort: true
})
})
.then(response => response.json())
.then(data => {
if (!data.success) {
console.error("API Error:", data.message);
return;
}
console.log(data.data);
let len = data.data.length;
document.getElementById("page-title").innerText = `Rezultati iskanja (${len}):`;
document.getElementById("entry-container").innerHTML = "";
if (len <= 0) {
document.getElementById("entry-container").innerHTML = `
Ni bilo najednih zadetkov za poizvedbo "${val}".
`;
return;
}
for (let entry of data.data) {
let build = `
${entry.kljuc}
${entry.tip}
${entry.vsebina}
${entry.primer}
`;
document.getElementById("entry-container").innerHTML += build;
}
})
.catch((error) => {
console.error("Error:", error);
});
}
document.getElementById("search-input").addEventListener("keydown", (event) => {
if (event.key === "Enter") {
event.preventDefault();
search();
}
});
function addEntry() {
window.open(new URL("new.html", window.location.href).href, "_top");
}
// DELAJ DELAJ
getLast();