var $j = jQuery.noConflict(); function ShowPicture(pic,picid){ screenwidth = screen.width; if (screenwidth>2000) screenwidth = 2000; MyWindow = window.open(pic , picid, "scrollbars=no,status=no,width="+screenwidth+",height=900,menubar=no,toolbar=no"); if (window.focus) { MyWindow.focus(); } // 1201 return false; } /* * JavaScript based on Pretty Date - (c) 2011 John Resig (ejohn.org) * Author Jaroslav Janda at gmail * Licensed under the MIT and GPL licenses. */ // Takes an ISO time and returns a string representing how // long ago the date represents. function prettyDate(time){ var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")), diff = (((new Date()).getTime() - date.getTime()) / 1000), day_diff = Math.floor(diff / 86400); var daytoday = new Date().getDay(); var dayart = date.getDay(); if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 3 ) return; if (diff>=43200) { if (dayart == daytoday) return "dnes"; dayart = dayart + 1; if (dayart == 7) dayart = 0; if (dayart == daytoday) return "včera"; return ""; } if (diff < 60) return "novinka"; if (diff < 120) return "před minutou"; if (diff < 3600) return "před " + Math.floor( diff / 60 ) + " minutami"; if (diff < 7200) return "před hodinou"; if (diff < 43200) return "před " + Math.floor( diff / 3600 ) + " hodinami"; return day_diff == 0 && ( diff < 60 && "novinka" || diff < 120 && "před minutou" || diff < 3600 && "před " + Math.floor( diff / 60 ) + " minutami" || diff < 7200 && "před hodinou" || diff < 43200 && "před " + Math.floor( diff / 3600 ) + " hodinami" || dayart != daytoday && (dayart+1) == daytoday && "včera" || diff >= 21600 && "dnes" ) || // day_diff == 1 && "včera" || day_diff > 0 && "" ; // day_diff < 7 && day_diff + " days ago" || // day_diff < 31 && Math.ceil( day_diff / 7 ) + " weeks ago"; } function replaceDate() { $j('div.opener-article>p.info>span').each(function(i,el) { var val = $j(this).attr('id'); val = prettyDate(val); if (val != '') { $j(this).text(val); } }); $j('div.article>p.info>span').each(function(i,el) { var val = $j(this).attr('id'); val = prettyDate(val); if (val != '') { $j(this).text(val); } }); $j('li>em>span').each(function(i,el) { var val = $j(this).attr('id'); val = prettyDate(val); if (val != '') { $j(this).text(val); } }); } $j(document).ready(function() { replaceDate(); $j("img.lazy").lazyload(); fetch('/like_card/') .then (res => res.json()) .then (showImg); }); setInterval(function() { replaceDate(); }, 60000); const showImg = (jsonImg) => { const imageCard = document.querySelector("#like_card") if (imageCard) { imageCard.dataset.id = jsonImg.id imageCard.innerHTML = ` ${jsonImg.name} ${jsonImg.count} ` const button = document.querySelector("#like_button") button.addEventListener("click", likeButton) } } const likeButton = (event) => { let id = event.target.parentElement.dataset.id if (id==undefined) { id = event.target.parentElement.parentElement.dataset.id } let likes = document.querySelector("#like_likes") num = parseInt(likes.innerText) num += 1 likes.innerText = num fetch ('/like_card/', { method: "POST", headers: { "Accept": 'application/json', "Content-Type": 'application/json' }, body: JSON.stringify ({ id: id }) }) }