bongzilla

Untitled

Nov 29th, 2021
770
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. $(document).ready(function(e) {
  3.     const COOKIE_NAME = "cookie-consent";
  4.     const cookiesWrap = "coock";
  5.     const cookiesConsentBtn = "coock-btn";
  6.  
  7.     function setCookie(name, value, days) {
  8.         var expires = "";
  9.         if (days) {
  10.             var date = new Date();
  11.             date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  12.             expires = "; expires=" + date.toUTCString();
  13.         }
  14.         document.cookie = name + "=" + (value || "") + expires + "; path=/";
  15.     }
  16.  
  17.     function getCookie(name) {
  18.         var nameEQ = name + "=";
  19.         var ca = document.cookie.split(';');
  20.         for (var i = 0; i < ca.length; i++) {
  21.             var c = ca[i];
  22.             while (c.charAt(0) == ' ') c = c.substring(1, c.length);
  23.             if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  24.         }
  25.         return null;
  26.     }
  27.  
  28.     function showPopup(popupSelector) {
  29.         const popupElement = document.getElementById(popupSelector);
  30.         popupElement.style.display = "flex";
  31.     }
  32.  
  33.     function closePopup(popupSelector) {
  34.         const popupElement = document.getElementById(popupSelector);
  35.         popupElement.style.display = "none";
  36.     }
  37.  
  38.     function attachConsentBtnListener(consentBtnSelector) {
  39.         document.getElementById(consentBtnSelector).addEventListener("click", function(e) {
  40.             setCookie(COOKIE_NAME, true, 10000);
  41.             closePopup(cookiesWrap)
  42.         });
  43.     }
  44.  
  45.     if(!getCookie(COOKIE_NAME)) {
  46.         attachConsentBtnListener(cookiesConsentBtn);
  47.         showPopup(cookiesWrap);
  48.     }
  49. });
  50. </script>
RAW Paste Data