var $ = jQuery; $(document).ready(function () { function reloadStatuses() { var keys = []; $(".tarot-status").each(function (index, obj) { keys.push($(obj).prop("id")); }) if (keys.length > 0) { $.ajax({ url: '//api-d80709.pyfjs.com', dataType: 'jsonp', data: { "keys": keys.join(",") }, success: function (data) { $(Object.keys(data)).each(function (index, key) { $(`*[id*=${key}]:visible`).each(function() { let isMan = $(this).hasClass("man") $(this).removeClass("green").removeClass("red") $(this).removeClass("tarot-1").removeClass("tarot-2").removeClass("tarot-3") $(this).find(".tarot-status-text").empty() if (data[key] == 1) { $(this).addClass("green") $(this).addClass("tarot-1") $(this).find(".tarot-status-text").html(isMan ? "Slobodan" : "Slobodna") } else if (data[key] == 2) { $(this).addClass("red") $(this).addClass("tarot-2") $(this).find(".tarot-status-text").html(isMan ? "Zauzet" : "Zauzeta") } else { $(this).addClass("tarot-3") $(this).find(".tarot-status-text").html(isMan ? "Nedostupan" : "Nedostupna") } }); }) } }); } } reloadStatuses(); setInterval(reloadStatuses, 5000); });