NikolayBezay

Soda stream form submit event + cookie saving.

Dec 8th, 2021 (edited)
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.30 KB | None | 0 0
  1. <script>
  2.     (function() {
  3.         var cookieEmailName = '__subscribedus';
  4.         var form = document.querySelector('.' + self.identifier + ' [tabindex] form');
  5.         form.setAttribute('bi-type', 'adoric-form');
  6.         form.setAttribute('bi-id', self.campaignTitle);
  7.  
  8.         function writeCookie(key, value, expires) {
  9.             var now = new Date();
  10.             var time = now.getTime();
  11.             time += 3600 * 1000 * 12;
  12.             now.setTime(time);
  13.             var cookieString = key + '=' + value + '; expires=' + now.toUTCString() + '; path=/';
  14.             if (expires) {
  15.                 cookieString += cookieString + '; expires=' + now.toUTCString() + '; path=/';
  16.             } else {
  17.                 cookieString += cookieString + '; expires=Fri, 31 Dec 9999 23:59:59 GMT"; path=/';
  18.             }
  19.             window.document.cookie = cookieString;
  20.             return value;
  21.         };
  22.  
  23.         function utf8_to_b64(str) {
  24.             return window.btoa(unescape(encodeURIComponent(str)));
  25.         }
  26.         form.addEventListener('submit', function() {
  27.             var emailField = form.querySelector('INPUT[name*="mail"]');
  28.             if (emailField) {
  29.                 writeCookie(cookieEmailName, utf8_to_b64(emailField.value));
  30.             }
  31.         });
  32.     })();
  33. </script>
Add Comment
Please, Sign In to add comment