- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<div id="rto-wrap">
<div class="rto-clock">
<span class="hours">00</span>
<span class="colon">:</span>
<span class="minutes">00</span>
<span class="colon">:</span>
<span class="seconds">00</span>
</div>
<div class="rto-callout-area">
<div class="rto-callout-text">
Order in the next 10 minutes and get <strong>$10</strong> off!
</div>
<div class="rto-callout-button">
<button>accept offer</button>
</div>
</div>
</div>
<script>
;(function() {
// uncomment when debugging - helps
//window.localStorage.clear()
var rs = {
pixp_cartCount: "1",
pixp_price: "169.00",
pixp_name: "TOTALe Online - Basic - 24 months"
}
var map = {
// If product price is 169, apply promo below to get it for 159
"169.00": {
'S5': "harajuku_S5",
'24': "harajuku_24M"
},
// If product price is 169, apply promo below to get it for 149
"159.00": {
'S5': "colosseum_S5",
'24': "colosseum_24M"
}
}
/*
* We only want to show if there's 1 product in cart,
* the product is either S5 or 24M, and the product
* price is one of the keys in `map` {} above
*/
if (rs.pixp_cartCount != "1")
{
return
}
if (Object.keys(map).indexOf(rs.pixp_price) == -1)
{
return
}
// Which level do we have in cart?
var level = null
if (rs.pixp_name.match(/24 months/i))
{
level = '24'
}
if (rs.pixp_name.match(/S5/i))
{
level = 'S5'
}
if (!level)
{
return
}
var minutes = 10
var endtime;
if (window.localStorage.getItem('rto_endtime'))
{
endtime = new Date(window.localStorage.getItem('rto_endtime'))
if (new Date > endtime)
{
stopClock()
return
}
}
else
{
endtime = new Date(new Date().getTime() + minutes *60*1000)
}
var $hours = $('span.hours')
var $minutes = $('span.minutes')
var $seconds = $('span.seconds')
// Starts and update the clock
function updateClock()
{
var timeleft = new Date( endtime - (new Date()) );
$hours.html( (timeleft.getHours() < 10 ? '0' : '') + timeleft.getHours())
$minutes.html( (timeleft.getMinutes() < 10 ? '0' : '') + timeleft.getMinutes())
$seconds.html( (timeleft.getSeconds() < 10 ? '0' : '') + timeleft.getSeconds())
window.localStorage.setItem('rto_endtime', endtime.toString())
if (Math.floor(timeleft/1000) <= 0)
{
stopClock()
}
}
// Stops the clock
function stopClock()
{
$('#rto-wrap').remove()
clearInterval(clockinterval)
}
// Fire up the clock. Update it every 1s
var $rto = $('#rto-wrap').detach()
$(document.body).append($rto)
$rto.css({display:'block'})
updateClock()
var clockinterval = setInterval(updateClock,1000);
$('.rto-callout-button > button').click(function(e) {
console.log('clicked')
window.localStorage.setItem('rto_endtime', new Date(-1).toString())
endtime = new Date(-1)
var promo_to_apply = map[rs.pixp_price][level]
jQuery('#coupon_code').val(promo_to_apply)
jQuery('#discountsubmit').click()
})
})()
</script>