daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest May 16th, 2018 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var utils = window.optimizely.get('utils');
  2. var $ = window.optimizely.get('jquery');
  3.  
  4. var html = '<aside id="v2-662744473353739-timer"><div class="countdown-wrapper"><p class="title"></p><span class="time-label"></span></div></div></aside>';
  5. var css = '#v2-662744473353739-timer{background-color:#189cac;padding:.4em 0 .4em 0;height:3.7em;text-align:center;position:fixed;top:0;width:100%;z-index:999}#v2-662744473353739-timer p{font-size:1.1em;color:#fff;float:left;text-align:right;margin:.5em 0}.countdown-wrapper{display:inline-block}#v2-662744473353739-timer .time-label{color:#fff;font-size:1.7em;float:left;padding-left:.6em}.navbar{position:fixed;top:0;width:100%;z-index:999}';
  6.  
  7. utils.waitForElement('su-cart-summary').then(function(element) {
  8.   $('head').append('<style>' + css + '</style>');
  9.  
  10.   var main = $('.main-nav');
  11.    
  12.   //add new html
  13.   main.after (html);
  14.  
  15.   var navBar = $("#navbar-top-collapse");
  16.   var timerElem = $("#v2-662744473353739-timer");
  17.  
  18.   var marginTop = navBar.height() + timerElem.height ();
  19.  
  20.   $('body').css ({"margin-top" : marginTop});
  21.   timerElem.css ({"margin-top" : navBar.height()});
  22.  
  23.   var labelText = "This deal is being reserved for you for:";
  24.  
  25.   if (angular.element(document.getElementsByTagName("BODY")[0]).scope().currentLang == "zh_CN")
  26.     labelText = '锁定此特价剩余时间:';
  27.    
  28.   timerElem.find (".title").text (labelText);
  29.  
  30.   var timerLabel = $("#v2-662744473353739-timer .time-label");
  31.   var minutes = 20;
  32.  
  33.   timerLabel.text (minutes + ":00");
  34.  
  35.   var timer = setInterval(function () {
  36.    
  37.     var presentTime = timerLabel.text ();
  38.     var timeArray = presentTime.split(/[:]+/);
  39.     var m = timeArray[0];
  40.     var s = checkSecond((timeArray[1] - 1));
  41.     if(s==59)
  42.       m=m-1;
  43.  
  44.     if(m == 0 && s == 0)
  45.       clearInterval(timer);
  46.    
  47.     timerLabel.text (m + ":" + s);
  48.   }, 1000);
  49.  
  50.   function checkSecond(sec) {
  51.     if (sec < 10 && sec >= 0) {sec = "0" + sec}; // add zero in front of numbers < 10
  52.     if (sec < 0) {sec = "59"};
  53.     return sec;
  54.   }
  55. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top