Sha256: 5b0a6a06a34d75493762d9c7188e7541d5bc1c2709da87bf5d5c61f67d50880b
Contents?: true
Size: 1.95 KB
Versions: 6
Compression:
Stored size: 1.95 KB
Contents
--- --- let userTrackingCountLimit='{{site.userTrackingCount}}'; const checkUsage = () => { const today = new Date().toDateString(); const usageCount = getCookie("featureUsageCount"); if (usageCount) { // User has already used the feature today if (usageCount >= Number(userTrackingCountLimit)) { showShareModal(); } else { incrementUsageCount(usageCount); } } else { // First usage of the day setCookie("featureUsageCount", 1, getExpirationDate()); } }; const incrementUsageCount = (count) => { const today = new Date().toDateString(); if (count >= Number(userTrackingCountLimit)) { showShareModal(); } else { count++; setCookie("featureUsageCount", count, getExpirationDate()); } }; const showShareModal = () => { document.getElementById("shareModal").style.display = "block"; }; const handleShare = () => { const usageCount = getCookie("featureUsageCount"); if (usageCount) { // Decrement the usage count by 1 if the user has already used the feature today setCookie("featureUsageCount", usageCount , getExpirationDate()); } document.getElementById("shareModal").style.display = "none"; }; const getCookie = (name) => { const cookies = document.cookie.split(";"); for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i].trim(); if (cookie.indexOf(name + "=") === 0) { return parseInt(cookie.substring((name + "=").length, cookie.length)); } } return null; }; const setCookie = (name, value, expires) => { document.cookie = `${name}=${value};expires=${expires};path=/`; }; const getExpirationDate = () => { const date = new Date(); date.setTime(date.getTime() + 24 * 60 * 60 * 1000); // 24 hours in milliseconds return date.toUTCString(); }; const socialShare=document.querySelectorAll('.social-share') if (socialShare) { Array.from(socialShare).map(item=>{ item.addEventListener('click',()=>{ handleShare() }) }) }
Version data entries
6 entries across 6 versions & 1 rubygems