Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.6 kB
4
Indexable
(function () {
  try {
    /* main variables */
    var debug = 0;
    var variation_name = "";
    var $;
    var closeButton = '<button class="eg-close-icon"></button>';
    var popupCookie = "popupshown";
    /* all Pure helper functions */

    var waitForElement = function (selector, trigger, delayInterval, delayTimeout) {
      var interval = setInterval(function () {
        if (
          document &&
          document.querySelector(selector) &&
          document.querySelectorAll(selector).length > 0
        ) {
          clearInterval(interval);
          trigger();
        }
      }, delayInterval);
      setTimeout(function () {
        clearInterval(interval);
      }, delayTimeout);
    }


    var getCookie = function (name) {
      var nameEQ = name + "=";
      var ca = document.cookie.split(';');
      for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
      }
      return null;
    }

    var setCookie = function (name, value, days) {
      var expires = "";
      if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toUTCString();
      }
      document.cookie = name + "=" + (value || "") + expires + "; path=/";
    }



    /* Variation Init */
    var init = function () {
      if (!document.querySelector('.eg-test-activated') && !getCookie(popupCookie)) {
        document.body.classList.add('eg-test-activated');
        setTimeout(function () {
          document.body.classList.add('eg-show-popup');
          document.querySelector('html body .entry-content>div:nth-child(13)>div').insertAdjacentHTML('afterbegin', closeButton);
          document.addEventListener('click', function (event) {
            var popup = document.querySelector('html body .entry-content>div:nth-child(13)');
            if ((
              event.target.classList.contains('eg-close-icon') ||
              event.target.parentNode.classList.contains('eg-close-icon')) || (popup && !popup.contains(event.target))
            ) {
              document.body.classList.remove('eg-show-popup');
              setCookie(popupCookie, true, 30);
            }
          });
        }, 15000)
      }
    }

    /* Initialize variation */
    waitForElement('html body .entry-content>div:nth-child(13)', init, 50, 15000);
  } catch (e) {
    if (debug) console.log(e, "error in Test" + variation_name);
  }
})();


Leave a Comment