Advertisement
tonytranmpv

tony

Apr 23rd, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. $(document).ready(function(){var cacheListCategoryTime=3;Notification.requestPermission(function(permission){});var local=JSON.parse(localStorage.getItem("listProduct"))||[];var category=JSON.parse(localStorage.getItem("listCategory"))||[];var categoryExpireTime=localStorage.getItem("categoryExpireTime")||0;var titleIntervalId=null;var isFirst=!local.length;$("#priceEnd").val(99999999999);$("#txtPercent").val(80);$("#startBtn").parent(".form-group").remove();var groupButton='<div class="form-group">'+'<button type="button" class="btn btn-primary" id="startBtn" style="margin-right: 15px;"><i class="glyphicon glyphicon-download"></i> Bắt đầu lần check mới</button>'+'<button type="button" class="btn btn-primary" id="continueBtn" style="display:none;"><i class="glyphicon glyphicon-repeat"></i> Tự động</button>'+'<img src="/images/loading.gif" alt="" id="loadImg" style="display: none; height: 30px">'+'</div>';groupButton=$(groupButton);groupButton.appendTo($("form.form-inline"));var continueBtn=groupButton.find("#continueBtn");var startBtn=groupButton.find("#startBtn");startBtn.click(function(){isFirst=!0;getCategory().then(function(){checkByLink(category.slice())})});continueBtn.click(function(){getCategory().then(function(){checkByLink(category.slice())})});if(!isFirst){continueBtn.show()}
  2. var callNotification=function(text,options){options.icon=options.icon||"http://www.lazada.vn/images/2014/icons/favicon-96x96.png";var notification=new Notification(text,{icon:options.icon});if(options.onclick){notification.onclick=options.onclick}
  3. sound()};var sound=function(){$('<div><audio autoplay="autoplay"><source src="'+"https://notificationsounds.com/message-tones/thrown-37/download/mp3"+'" type="audio/ogg" /></audio></div>').appendTo("body")}
  4. function getCategory(){showPercent(1);$('#listProduct').html('');$('#startBtn').hide();$('#continueBtn').hide();$('#loadImg').show();$('#percentBar').show();$('#percent').show();$('form input').prop('disabled',!0);defaultTitle("Tự động được bật");if($.now()>categoryExpireTime||!category.length){return $.post('/lazada/get-category',{},function(result){if(result.length){categoryExpireTime=cacheListCategoryTime*1000*3600+$.now();localStorage.setItem("categoryExpireTime",categoryExpireTime);category=result;localStorage.setItem("listCategory",JSON.stringify(category))}})}
  5. return new Promise(function(res,rej){res()})}
  6. function showPercent(number){$('#process').css('width',number+'%');$('#percent').html(number+'%')}
  7. checkByLink=function(categoryArr){if(!categoryArr.length){$(document).trigger("checkDone");var newProduct=$("#listProduct > div > div p a").length;if(newProduct){$('#startBtn').show();$('#continueBtn').show();$('#loadImg').hide();$('form input').prop('disabled',!1);localStorage.setItem("listProduct",JSON.stringify(local));var onclick=function(event){event.preventDefault();continueBtn.click();this.close()}
  8. if(isFirst){callNotification("Hoàn thành lần chạy đầu tiên, Click tự động hoặc click vào đây để chạy tự động lại",{onclick:onclick});var title1="Hoàn thành lần chạy đầu tiên"}else{callNotification("Có sản phẩm mới, Click tự động hoặc click vào đây để chạy tự động lại",{onclick:onclick});var title1="!!Có hàng mới"}
  9. var title2="Click tự động để chạy tự động lại";defaultTitle("");changeTitle(title1,title2)}else{continueBtn.click()}
  10. return!1}
  11. url=categoryArr[0];percent=$('#txtPercent').val();price_start=$('#priceStart').val();price_end=$('#priceEnd').val();$.post('/lazada/product',{url:url,percent:percent,price_start:price_start,price_end:price_end},function(result){for(i=0;i<result.length;i++){var href=result[i].link;href=decodeURIComponent(href.substring(href.indexOf("http"),href.length));if($.inArray(href,local)==-1){if(!isFirst){var onclick=(function(href){return function(e){event.preventDefault();window.open(href,'_blank');this.close()}})(href);callNotification(result[i].name+" ("+result[i].price+")",{icon:result[i].img,onclick:onclick});defaultTitle("");changeTitle("!!Có hàng mới","Báo vậy thôi")}
  12. local.push(href);htmlx='<div class="col-lg-3 col-md-4" style="margin-bottom: 10px">'+'<div style="position: relative;border: 1px solid #ccc; padding: 5px; min-height: 400px">'+'<img style="width: 100%" src="'+result[i].img+'">'+'<p><a target="_blank" href="'+href+'" style="">'+result[i].name+'</a></p>'+'<b class="text-danger">'+result[i].price+'</b>'+'<br>'+'<span style="text-decoration: line-through; color: #000">'+result[i].oldprice+'</span>'+'<div class="discount" style="background: red; position: absolute; top: 0; left: 0; padding: 5px">'+'<h4 style="color: #fff">-'+result[i].discount+'%</h4>'+'</div>'+'<div class="sosanh" style="background: green; position: absolute; top: 0; right: 0; padding: 5px">'+'<a target="_blank" style="display: block; color: #fff;" href="https://websosanh.vn/s/'+result[i].name+'.htm">So sánh</a>'+'</div>'+'</div>'+'</div>';$('#listProduct').append(htmlx)}}
  13. var percent=(parseInt(category.length-categoryArr.length)+1)*100/category.length;showPercent(Math.ceil(percent));setTimeout(function(){categoryArr.shift();checkByLink(categoryArr)},100)},'json').fail(function(){$('#startBtn').show();$('#loadImg').hide();$('form input').prop('disabled',!1);if(isFirst){var onclick=function(event){event.preventDefault();startBtn.click();this.close()}
  14. callNotification("Đã xảy ra lỗi, Click vào đây để chạy lại",{onclick:onclick});var title1="Click chạy lại"}else{$('#continueBtn').show();var onclick=function(event){event.preventDefault();continueBtn.click();this.close()}
  15. callNotification("Đã xảy ra lỗi, Click tự động hoặc click vào đây để chạy tự động lại",{onclick:onclick});var title1="Click chạy lại"}
  16. var title2="Đã xảy ra lỗi";defaultTitle("");changeTitle(title1,title2)})}
  17. function changeTitle(title1,title2){var currentTitle=title1;titleIntervalId=setInterval(function(){document.title=currentTitle;currentTitle=currentTitle==title1?title2:title1},1500)}
  18. function defaultTitle(title){clearInterval(titleIntervalId);document.title=title}})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement