forked from ToX82/cookie-bar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookiebar-latest.min.js
1 lines (1 loc) · 5.59 KB
/
cookiebar-latest.min.js
1
function setupCookieBar(){function e(){if(document.cookie.length>0||window.localStorage.length>0){var e=r();void 0===e?w=!0:I=!0}else w=!1;p("always")&&(w=!0),!0===w&&!1===I&&t()}function t(){var e=a(),t="";p("theme")&&(t="-"+p("theme"));var n=B.replace(/[^\/]*$/,""),i=B.indexOf(".min")>-1?".min":"",r=document.createElement("link");r.setAttribute("rel","stylesheet"),r.setAttribute("href",n+"themes/cookiebar"+t+i+".css"),document.head.appendChild(r);var c=new XMLHttpRequest;c.open("GET",n+"lang/"+e+".html",!0),c.onreadystatechange=function(){if(4===c.readyState&&200===c.status){var e=document.createElement("div");e.innerHTML=c.responseText,document.getElementsByTagName("body")[0].appendChild(e),g=document.getElementById("cookie-bar"),k=document.getElementById("cookie-bar-button"),b=document.getElementById("cookie-bar-button-no"),f=document.getElementById("cookie-bar-prompt"),v=document.getElementById("cookie-bar-prompt-button"),E=document.getElementById("cookie-bar-prompt-close"),promptContent=document.getElementById("cookie-bar-prompt-content"),h=document.getElementById("cookie-bar-no-consent"),thirdparty=document.getElementById("cookie-bar-thirdparty"),tracking=document.getElementById("cookie-bar-tracking"),scrolling=document.getElementById("cookie-bar-scrolling"),privacyPage=document.getElementById("cookie-bar-privacy-page"),privacyLink=document.getElementById("cookie-bar-privacy-link"),mainBarPrivacyLink=document.getElementById("cookie-bar-main-privacy-link"),p("showNoConsent")||(h.style.display="none",b.style.display="none"),p("blocking")&&(d(f,500),E.style.display="none"),p("thirdparty")&&(thirdparty.style.display="block"),p("tracking")&&(tracking.style.display="block"),p("hideDetailsBtn")&&(v.style.display="none"),p("scrolling")&&(scrolling.style.display="inline-block"),p("top")?(g.style.top=0,m("top")):(g.style.bottom=0,m("bottom")),p("privacyPage")&&(privacyLink.href=o(),privacyPage.style.display="inline-block"),p("showPolicyLink")&&p("privacyPage")&&(mainBarPrivacyLink.href=o(),mainBarPrivacyLink.style.display="inline-block"),y(),d(g,250),m()}},c.send()}function o(){return decodeURIComponent(p("privacyPage"))}function n(){var e=document.getElementsByTagName("script");for(i=0;i<e.length;i+=1)if(e[i].hasAttribute("src")&&(path=e[i].src,path.indexOf("cookiebar")>-1))return path}function a(){var e=p("forceLang");return!1===e&&(e=navigator.language||navigator.userLanguage),e=e.substr(0,2),CookieLanguages.indexOf(e)<0&&(e="en"),e}function r(){var e=document.cookie.match(/(;)?cookiebar=([^;]*);?/);return null==e?void 0:decodeURI(e[2])}function c(e,t){var o=30;p("remember")&&(o=p("remember"));var n=new Date;n.setDate(n.getDate()+parseInt(o));var i=encodeURI(t)+(null===o?"":"; expires="+n.toUTCString()+";path=/");document.cookie=e+"="+i}function l(){document.cookie.split(";").forEach(function(e){document.cookie=e.replace(/^\ +/,"").replace(/\=.*/,"=;expires="+(new Date).toUTCString()+";path=/")}),localStorage.clear()}function d(e,t){var o=e.style;o.opacity=0,o.display="block",function e(){!((o.opacity-=-.1)>.9)&&setTimeout(e,t/10)}()}function s(e,t){var o=e.style;o.opacity=1,function e(){(o.opacity-=.1)<.1?o.display="none":setTimeout(e,t/10)}()}function m(e){setTimeout(function(){var t=document.getElementById("cookie-bar").clientHeight,o=document.getElementsByTagName("body")[0],n=o.currentStyle||window.getComputedStyle(o);switch(e){case"top":o.style.marginTop=parseInt(n.marginTop)+t+"px";break;case"bottom":o.style.marginBottom=parseInt(n.marginBottom)+t+"px"}},300)}function u(){var e=document.getElementById("cookie-bar").clientHeight;if(p("top")){var t=parseInt(document.getElementsByTagName("body")[0].style.marginTop);document.getElementsByTagName("body")[0].style.marginTop=t-e+"px"}else{var o=parseInt(document.getElementsByTagName("body")[0].style.marginBottom);document.getElementsByTagName("body")[0].style.marginBottom=o-e+"px"}}function p(e){var t=B.split(e+"=");return!!t[1]&&t[1].split(/[&?]+/)[0]}function y(){if(k.addEventListener("click",function(){c("cookiebar","CookieAllowed"),u(),s(f,250),s(g,250),p("refreshPage")&&window.location.reload()}),b.addEventListener("click",function(){var e=h.textContent.trim(),t=window.confirm(e);!0===t&&(l(),c("cookiebar","CookieDisallowed"),u(),s(f,250),s(g,250))}),v.addEventListener("click",function(){d(f,250)}),E.addEventListener("click",function(){s(f,250)}),p("scrolling")){var e=document.body.getBoundingClientRect().top,t=!1;window.addEventListener("scroll",function(){!1===t&&(document.body.getBoundingClientRect().top-e>250||document.body.getBoundingClientRect().top-e<-250)&&(c("cookiebar","CookieAllowed"),u(),s(f,250),s(g,250),t=!0,p("refreshPage")&&window.location.reload())})}}var g,k,b,f,v,E,h,B=n(),w=!1,I=!1,T=r();if("CookieDisallowed"==T&&(l(),c("cookiebar","CookieDisallowed")),void 0===T)if(p("noGeoIp"))w=!0,e();else{var L=new XMLHttpRequest;L.open("GET","https://freegeoip.app/json/",!0),L.onreadystatechange=function(){if(4===L.readyState){if(clearTimeout(C),200===L.status){var t=JSON.parse(L.responseText).country_code;cookieLawStates.indexOf(t)>-1?w=!0:(I=!0,c("cookiebar","CookieAllowed"),p("refreshPage")&&window.location.reload())}else w=!0;e()}};var C=setTimeout(function(){console.log("cookieBAR - Timeout for ip geolocation"),L.onreadystatechange=function(){},L.abort(),w=!0,e()},1500);L.send()}}var CookieLanguages=["bg","br","ca","cs","da","de","el","en","es","fi","fr","hr","hu","it","nl","no","pl","pt","ro","ru","se","sk","sl"],cookieLawStates=["AT","BE","BG","BR","CY","CZ","DE","DK","EE","EL","ES","FI","FR","GB","HR","HU","IE","IT","LT","LU","LV","MT","NL","NO","PL","PT","RO","SE","SI","SK"];document.addEventListener("DOMContentLoaded",function(){setupCookieBar()});