dodatki
This commit is contained in:
@@ -8,9 +8,9 @@ function getCookie(name) {
|
||||
function getKey() {
|
||||
const url = `https://ssnj.dcrubro.com/api/vnos`;
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
pk: kljuc
|
||||
@@ -19,7 +19,7 @@ function getKey() {
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (!data.success) {
|
||||
console.error('API Error:', data.message);
|
||||
console.error("API Error:", data.message);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -96,39 +96,39 @@ function getKey() {
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
console.error("Error:", error);
|
||||
});
|
||||
}
|
||||
|
||||
getKey();
|
||||
|
||||
function initVoting(entryData) {
|
||||
const upBtn = document.getElementById('vote-up');
|
||||
const downBtn = document.getElementById('vote-down');
|
||||
const sumEl = document.getElementById('vote-sum');
|
||||
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');
|
||||
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);
|
||||
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);
|
||||
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' },
|
||||
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())
|
||||
@@ -136,29 +136,29 @@ function initVoting(entryData) {
|
||||
const v = obj?.vote || 0;
|
||||
setActive(v);
|
||||
})
|
||||
.catch(err => console.error('semvolil error', err));
|
||||
.catch(err => console.error("semvolil error", err));
|
||||
|
||||
upBtn.addEventListener('click', () => submitVote(1));
|
||||
downBtn.addEventListener('click', () => submitVote(-1));
|
||||
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; }
|
||||
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' },
|
||||
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' },
|
||||
return fetch("https://ssnj.dcrubro.com/api/vnos", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ pk: kljuc })
|
||||
});
|
||||
})
|
||||
@@ -170,6 +170,6 @@ function initVoting(entryData) {
|
||||
setActive(sendVote);
|
||||
}
|
||||
})
|
||||
.catch(err => console.error('vote error', err));
|
||||
.catch(err => console.error("vote error", err));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user