Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- (function () {
- var TIME_SHOW_CAMPAIN = 3000;
- var WAITING_TIMER_COUNTER = 60;
- var HALF_OF_THE_SECOND = 500;
- function getCartCounter() {
- var counter = document.querySelector('.page_header_minicart .counter .counter-number');
- if (counter) {
- counter = counter.textContent;
- }
- return counter;
- }
- function checkCounter(counter) {
- var currentCounter = getCartCounter();
- if (counter && currentCounter && parseInt(counter) < parseInt(currentCounter)) {
- window.adoric && window.adoric.trigger('showMiniCartOnClick');
- }
- }
- function campaignTriggering() {
- var addToCartButton = document.querySelector('#product-addtocart-button');
- var counter = getCartCounter();
- if (addToCartButton && counter) {
- addToCartButton.addEventListener('click', function () {
- setTimeout(function () {
- checkCounter(counter);
- }, TIME_SHOW_CAMPAIN);
- });
- addToCartButton.addEventListener('touchend', function () {
- setTimeout(function () {
- checkCounter();
- }, TIME_SHOW_CAMPAIN);
- });
- }
- }
- function waitPageSelector() {
- WAITING_TIMER_COUNTER--;
- var nativePageSelector = document.querySelector('#product-addtocart-button');
- if (!nativePageSelector && nativePageSelector.textContent.length == 0 && WAITING_TIMER_COUNTER > 0) {
- setTimeout(waitPageSelector, HALF_OF_THE_SECOND);
- } else {
- campaignTriggering();
- }
- }
- waitPageSelector();
- })();
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement