1function egaFlashSale() { 2 // call product ajax 3 // init countdown 4 $('.flashsale').show() 5 if (!window.falshSale) return 6 Date.prototype.addDays = function (days) { 7 var date = new Date(this.valueOf()); 8 date.setDate(date.getDate() + days); 9 return date; 10 } 11 Date.prototype.addHours = function (hours) { 12 this.setTime(this.getTime() + ((hours) * 60 * 60 * 1000)); 13 return this; 14 } 15 const getDays = (times) => Math.floor((times / (1000 * 60 * 60 * 24))) 16 const getHours = (times) => Math.floor((times % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); 17 const getMinutes = (times) => Math.floor((times % (1000 * 60 * 60)) / (1000 * 60)); 18 const getSeconds = (times) => Math.floor((times % (1000 * 60)) / 1000); 19 function randomQty() { 20 var minQty = +window.falshSale.percentMin; 21 var maxQty = +window.falshSale.percentMax; 22 minQty = Math.ceil(minQty); 23 maxQty = Math.floor(maxQty); 24 var qty = Math.floor(Math.random() * (maxQty - minQty + 1)) + minQty; 25 qty = parseInt(qty); 26 if (qty <= minQty) { 27 qty = minQty; 28 } 29 if (qty > maxQty) { 30 qty = maxQty; 31 } 32 return qty 33 } 34 function renderProgress(item) { 35 let id = $(item).data('pdId') 36 let inventory = parseInt($(item).data('inventoryQuantity')) 37 let available = $(item).data('available') 38 let management = $(item).data('management') 39 let soldQuantity = $(item).data('soldQuantity') 40 let progress = $(item).find('.flashsale___percent') 41 let soldNumber = $(item).find('.flashsale__sold-qty') 42 let label = $(item).find('.flashsale__label') 43 let maxInStock = parseInt(window.falshSale.maxInStock) 44 let percent, stock, soldQty 45 flashSaleStorage[id] = flashSaleStorage.hasOwnProperty(id) ? flashSaleStorage[id] : {} 46 if(flashSaleStorage[id] && management && flashSaleStorage[id].inventory !== inventory){ 47 if( flashSaleStorage[id].inventory > inventory ){ 48 flashSaleStorage[id].soldQty = flashSaleStorage[id].soldQty + flashSaleStorage[id].inventory - inventory; 49 50 }else{ 51 flashSaleStorage[id] = {} 52 } 53 } 54 if (useSoldQuantity) { 55 soldQty = parseInt(soldQuantity) 56 stock = parseInt(inventory) + soldQty 57 percent = Math.round(soldQty * 100 / stock) 58 } else { 59 stock = flashSaleStorage[id].stock || maxInStock 60 percent = !flashSaleStorage[id].soldQty ? randomQty() : Math.round(flashSaleStorage[id].soldQty * 100 / stock) 61 soldQty = !flashSaleStorage[id].soldQty ? Math.round(percent * stock / 100) : flashSaleStorage[id].soldQty 62 if( Math.round(inventory *100 / maxInStock ) <= 2 ){ 63 percent = 98 64 } 65 } 66 if(!available && inventory == 0){ 67 percent = 100 68 } 69 if(available && inventory <= 0){ 70 percent = 98 71 } 72 flashSaleStorage[id].soldQty = soldQty 73 flashSaleStorage[id].timestamp = !flashSaleStorage[id].timestamp ? new Date().getTime() : flashSaleStorage[id].timestamp 74 flashSaleStorage[id].stock = stock 75 flashSaleStorage[id].inventory = inventory 76 flashSaleStorage[id].mangement = management 77 if(quantityType !== 'inventory'){ 78 percent = percent == 100 && available ? 90 : percent 79 progress.css('width', `${percent < 90 || (percent > 90 && percent < 100) ? percent : 90}%`) 80 if (percent >= 98) { 81 label.html(` ð¥ ${window.falshSale.outOfStockSoonText}`) 82 } 83 84 if (percent == 100 || !available) { 85 label.html('Hết hà ng') 86 progress.css('width', `100%`) 87 } 88 89 if (percent <= 0 && available) { 90 label.html(window.flashSale.openingText) 91 progress.css('width', `5%`) 92 } 93 }else{ 94 percent = 100 - percent 95 percent = percent == 0 && available ? 10 : percent 96 progress.css('width', `${percent > 10 || (percent > 0 && percent < 10) ? percent : 10}%`) 97 if (percent <= 10) { 98 label.html(' ð¥ ${window.falshSale.outOfStockSoonText}') 99 } 100 101 if (percent == 0 || !available) { 102 label.html('Hết hà ng') 103 progress.css('width', `100%`) 104 } 105 } 106 if (!useSoldQuantity) soldNumber.text(quantityType == 'inventory' ? stock - soldQty : soldQty) 107 } 108 function updateQty() { 109 if (flashSaleStorage && Object.keys(flashSaleStorage).length) { 110 Object.keys(flashSaleStorage).map(key => { 111 let item = flashSaleStorage[key] 112 let current = new Date().getTime() 113 let distance = (current - item.timestamp) / 1000 / 60 114 let qty = distance > loopTime ? Math.round(distance / loopTime) : 0 115 if(!item.mangement ){ item.soldQty += qty 116 item.soldQty = item.soldQty > item.stock ? item.stock : item.soldQty 117 item.timestamp = distance > loopTime ? current : item.timestamp 118 } 119 }) 120 localStorage.setItem('flashSaleStorageItem', JSON.stringify(flashSaleStorage)) 121 return flashSaleStorage 122 } 123 return 124 125 } 126 function renderCountDown(distance) { 127 // Time loop from settings 128 let html = []; 129 let days = getDays(distance) 130 let hours = `<div><div class="ega-badge-ctd__item ega-badge-ctd__h">${getHours(distance) >= 10 ? getHours(distance) : `0${getHours(distance)}`}</div><span>Giá»</span> </div>` 131 let minutes = `<div><div class="ega-badge-ctd__item ega-badge-ctd__m">${getMinutes(distance) >= 10 ? getMinutes(distance) : `0${getMinutes(distance)}`}</div><span>Phút</span></div>` 132 let seconds = `<div><div class="ega-badge-ctd__item ega-badge-ctd__s">${getSeconds(distance) >= 10 ? getSeconds(distance) : `0${getSeconds(distance)}`}</div><span>Giây</span></div>` 133 html = [hours, minutes, seconds] 134 if (days > 0) html.unshift(`<div><div class="ega-badge-ctd__item ega-badge-ctd__d">${days >= 10 ? days : `0${days}`}</div><span>Ngà y</span></div>`) 135 return `<div class="ega-badge-ctd"> 136${html.join(` <div class="ega-badge-ctd__colon" > : </div>`)} 137 138</div>`; 139 } 140 function calcCountDown(startTime, endTime) { 141 let distance = 0 142 let now = new Date().getTime() 143 if (now >= startTime && now <= endTime) { 144 distance = (endTime - now); 145 146 return distance 147 } 148 return distance 149 } 150 let now = new Date() 151 let loopTime = 6; 152 let { type, 153 dateStart, 154 dateFinish, 155 hourStart,
156 hourFinish, 157 dayLoop, 158 activeDay, 159 finishAction, 160 finishLabel, 161 useSoldQuantity, 162 quantityType 163 } = window.falshSale 164 var flashSaleStorage = JSON.parse(localStorage.getItem('flashSaleStorageItem')) || {} 165 let flashSaleSetting = JSON.parse(localStorage.getItem('flashSale')) || {} 166 if (JSON.stringify(flashSaleSetting) != JSON.stringify(window.falshSale)) { 167 let setting1 = Object.assign({},flashSaleSetting) 168 let setting2 = Object.assign({},window.falshSale) 169 let storageDate = flashSaleSetting.timestamp 170 if((+activeDay === 7 && !storageDate) || 171 (new Date(storageDate).getDay() !== new Date().getDay())){ 172 flashSaleStorage = {} 173 } 174 delete setting1.timestamp 175 delete setting2.timestamp 176 if(JSON.stringify(setting1) != JSON.stringify(setting2)){ 177 flashSaleStorage = {} 178 } 179 } 180 localStorage.setItem('flashSale', JSON.stringify(window.falshSale)) 181 182 let distance = 0, startTime, endTime; 183 if (type === 'hours' && (new Date().getDay() === +activeDay || +activeDay === 7)) { 184 // expireTime 185 hourStart = hourStart.split(':') 186 // check is start time valid 187 // convert start time to time stamp 188 startTime = new Date().setHours(hourStart[0] != '24' ? hourStart[0] : '00', hourStart[1] || '00', '00') 189 endTime = new Date(startTime).addHours(+hourFinish).getTime() 190 //check is flash sale started || finished 191 } 192 if (type === 'days') { 193 var pattern = /(\d{2})\/(\d{2})\/(\d{4})/; 194 startTime = new Date(dateStart.replace(pattern, '$3-$2-$1')) 195 startTime = startTime.setHours('00', '00', '00') 196 // check valid date 197 endTime = new Date(startTime).addDays(+dateFinish).getTime() 198 199 } 200 distance = calcCountDown(startTime, endTime); 201 if (distance > 0) { 202 203 setInterval(function () { 204 distance = calcCountDown(startTime, endTime); 205 $(`.flashsale__countdown`).html(renderCountDown(distance)) 206 }, 1000) 207 let dotAnimation = `<span class="ega-dot"><span class="ega-ping"></span></span>` 208 if(!$('.flashsale__title .ega-dot').length ) $(`.flashsale__title`).append(dotAnimation) 209 $(`.flashsale__countdown`).html(renderCountDown(distance)) 210 $(`.flashsale__countdown-label`).show() 211 212 var isRendered = !useSoldQuantity && updateQty() 213 $('.flashsale__item').each(function () { renderProgress(this) }) 214 if (!useSoldQuantity) { 215 let start = 0 216 setInterval(function () { 217 if(start){ 218 updateQty() 219 $('.flashsale__item').each(function () { 220 renderProgress(this) 221 }) 222 } 223 start +=1 224 }, loopTime * 1000) 225 } 226 $(`.flashsale__bottom`).show() 227 !isRendered && localStorage.setItem('flashSaleStorageItem', JSON.stringify(flashSaleStorage)) 228 } else { 229 if (finishAction == 'show') { 230 $(`.flashsale__countdown`).html('') 231 $(`.flashsale__countdown-label`).html(finishLabel).show() 232 } 233 $('#ega-product-detail .flashsale ').remove() 234 $(`.flashsale__bottom`).remove() 235 finishAction == 'hide' && $(`.flashsale`).remove() 236 localStorage.removeItem('flashSaleStorageItem') 237 } 238 239} 240let isload = 0; 241$(document).ready(()=>{ 242try{ 243egaFlashSale() 244 }catch(e){ 245 console.log(e) 246 } 247})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.