Skip to content

Instantly share code, notes, and snippets.

@arturmkrtchyan
Last active March 10, 2021 20:30
Show Gist options
  • Save arturmkrtchyan/f89f821de86c637d3ecb5e5665d07606 to your computer and use it in GitHub Desktop.
Save arturmkrtchyan/f89f821de86c637d3ecb5e5665d07606 to your computer and use it in GitHub Desktop.

part 1

<script>
document.addEventListener("DOMContentLoaded", function() {
    $('[id=sw-email-capture-submit-btn]').click(function() {
          if($('.sw-input-invalid').length) {
              return;
          }
          setTimeout(function(){
              const domain = window.location.host;
              setCookie('emailCaptureForListOfEvents', 'done', 90);
              window.location.href= 'https://' + domain + '/list-of-events';
          }, 1500);
    });

    function setCookie(name, value, days) {
        const date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        const expires = "expires="+ date.toUTCString();
        document.cookie = name + "=" + value + ";" + expires + ";" + "samesite=none;secure;";
    }
});
</script>

part 2

<script>
document.addEventListener("DOMContentLoaded", function() {
    var domain = window.location.host;
    const emailCaptureForListOfEvents = getCookie('emailCaptureForListOfEvents');
    if(emailCaptureForListOfEvents !== 'done') {
        window.location.href= 'https://' + domain + '/';
    }

    function getCookie(cookieName) {
        var name = cookieName + "=";
        var decodedCookie = decodeURIComponent(document.cookie);
        var ca = decodedCookie.split(';');
        for(var i = 0; i <ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
            c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
            }
        }
        return "";
    }
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment