setTimeout(function(){
(function() {
try{
let links = document.querySelectorAll('a');
let hrefStart = new RegExp("^https\:\/\/v\.hvl\.no\/pameldingssystem\/index\.php","i");
if (!document.getElementById('pameldingsInfo')){
links.forEach(function(link){
//let currLink = new URL(link);
//res.innerText = thisUrl.searchParams.get('snerbel');
//let linkObj = new URL(link);
//console.info(JSON.stringify().toJSON(linkObj),'',' ');
if (hrefStart.test(link.href)){
let splitUrl = link.href.split('?');
if (!!splitUrl[1]){
let params = JSON.parse('{"' + splitUrl[1].replace('=','":"').replace('&','","') + '"}');
if (!!params.id){
try{
let u = 'https://v.hvl.no/pameldingssystem/statusInfo.php?callback=RAW&id=' + parseInt(params.id);
fetch(u)
.then(response => response.json())
.then(json => {
if (json.Error == false){
if (!!json.Data){
// callback({"Error":false,"Data":{"NumOfApplicants":"34","NumOfSeats":"0","Expiration":"1638053999","Name":"Julebord Haugesund, des. 2021","ContactMail":"Maria.Svanoe@hvl.no","ExpirationDate":"27.11.2021","Id":"2122"}})
let msgOut = document.createElement('span');
msgOut.style.fontFamily = 'Arial,sans-serif';
msgOut.innerHTML = `
Frist: ${json.Data.ExpirationDate}
`;
link.parentNode.appendChild(msgOut);
}else{
console.error('Feil ved innhenting av status: ' + JSON.stringify(json));
}
}else{
console.error('Sjekk for antall påmeldte og frist returnerte: ' + JSON.stringify(json));
}
})
.catch(e => console.error('Problem med å hente in antall påmeldte og frist fra ' + u + ', feil: ' + e))
}catch(e){
let u = 'https://v.hvl.no/pameldingssystem/applicationInfo.php?eventids=' + parseInt(params.id);
fetch(u)
.then(response => response.json())
.then(json => {
if (!!json.success){
if (!!json.data[parseInt(params.id)]){
let msgOut = document.createElement('span');
msgOut.style.fontFamily = 'Arial,sans-serif';
msgOut.innerHTML = ' Påmeldte til nå: ' + json.data[parseInt(params.id)] + '';
link.parentNode.appendChild(msgOut);
}else{
console.error('ID ble ikke funnet: ' + JSON.stringify(json));
}
}else{
console.error('Sjekk for antall påmeldte returnerte: ' + JSON.stringify(json));
}
})
.catch(e => console.error('Problem med å hente in antall påmeldte fra ' + u + ', feil: ' + e))
}
}
}
}
});
}
}catch(e){
console.error('Kunne ikkje vise antal påmelde: ' + e);
}
})();
},500);