2 lines
5.5 KiB
JavaScript
2 lines
5.5 KiB
JavaScript
var CookieLanguages=["ca","cs","da","de","en","es","fr","hu","it","nl","pt","ro","sk"];var cookieLawStates=["AT","BE","BG","CY","CZ","DE","DK","EE","EL","ES","FI","FR","GB","HR","HU","IE","IT","LT","LU","LV","MT","NL","PL","PT","RO","SE","SI","SK"];function setupCookieBar(){var t=A();var p;var c;var B;var w;var b;var h;var o;var z;var r;var E;var j;var f=false;var l=false;if(C()=="CookieDisallowed"){k();u("cookiebar","CookieDisallowed")}var v=new XMLHttpRequest();v.open("GET","//freegeoip.io/json/",true);v.onreadystatechange=function(){if(v.readyState===4&&v.status===200){clearTimeout(q);var G=JSON.parse(v.responseText).country_code;if(cookieLawStates.indexOf(G)>-1){f=true}else{l=true}}};var q=setTimeout(e,1500);function e(){console.log("cookieBAR - Timeout for ip geolocation");v.abort();f=true}v.send();if(document.cookie.length>0||window.localStorage.length>0){var a=C();if(a===undefined){f=true}else{l=true}}if(D("always")){f=true}if(f===true&&l===false){m()}function m(){var G=g();var K="";if(D("theme")){K="-"+D("theme")}var J=t.replace(/[^\/]*$/,"");var L=(t.indexOf(".min")>-1)?".min":"";var H=document.createElement("link");H.setAttribute("rel","stylesheet");H.setAttribute("href",J+"cookiebar"+K+L+".css");document.head.appendChild(H);var I=new XMLHttpRequest();I.open("GET",J+"/lang/"+G+".html",true);I.onreadystatechange=function(){if(I.readyState===4&&I.status===200){var N=document.createElement("div");N.innerHTML=I.responseText;document.getElementsByTagName("body")[0].appendChild(N);p=document.getElementById("cookie-bar");c=document.getElementById("cookie-bar-button");B=document.getElementById("cookie-bar-button-no");w=document.getElementById("cookie-bar-prompt");b=document.getElementById("cookie-bar-prompt-button");h=document.getElementById("cookie-bar-prompt-close");o=document.getElementById("cookie-bar-prompt-content");z=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");if(!D("showNoConsent")){z.style.display="none";B.style.display="none"}if(D("blocking")){x(w,500);h.style.display="none"}if(D("thirdparty")){thirdparty.style.display="block"}if(D("tracking")){tracking.style.display="block"}if(D("scrolling")){scrolling.style.display="inline-block"}if(D("top")){p.style.top=0;s("top")}else{p.style.bottom=0;s("bottom")}if(D("privacyPage")){var M=decodeURIComponent(D("privacyPage"));privacyLink.href=M;privacyPage.style.display="inline-block"}n();x(p,250);s()}};I.send()}function A(){var G=document.getElementsByTagName("script");for(i=0;i<G.length;i+=1){if(G[i].hasAttribute("src")){path=G[i].src;if(path.indexOf("cookiebar")>-1){return path}}}}function g(){var G=D("forceLang");if(G===false){G=navigator.language||navigator.userLanguage}G=G.substr(0,2);if(CookieLanguages.indexOf(G)<0){G="en"}return G}function y(H){var K=[];var I,G,L,J=document.cookie.split(";");for(I=0;I<J.length;I+=1){G=J[I].substr(0,J[I].indexOf("="));L=J[I].substr(J[I].indexOf("=")+1);G=G.replace(/^\s+|\s+$/g,"");K.push(G)}H.innerHTML=K.join(", ")}function C(){var G=document.cookie.match(/(;)?cookiebar=([^;]*);?/);if(G==null){return undefined}else{return decodeURI(G[2])}}function u(G,J){var I=30;if(D("remember")){I=D("remember")}var K=new Date();K.setDate(K.getDate()+parseInt(I));var H=encodeURI(J)+((I===null)?"":"; expires="+K.toUTCString()+";path=/");document.cookie=G+"="+H}function k(){document.cookie.split(";").forEach(function(G){document.cookie=G.replace(/^\ +/,"").replace(/\=.*/,"=;expires="+new Date().toUTCString()+";path=/")});localStorage.clear()}function x(H,I){var G=H.style;G.opacity=0;G.display="block";(function J(){(G.opacity-=-0.1)>0.9?null:setTimeout(J,(I/10))})()}function d(H,I){var G=H.style;G.opacity=1;(function J(){(G.opacity-=0.1)<0.1?G.display="none":setTimeout(J,(I/10))})()}function s(G){setTimeout(function(){var I=document.getElementById("cookie-bar").clientHeight;var J=document.getElementsByTagName("body")[0];var H=J.currentStyle||window.getComputedStyle(J);switch(G){case"top":J.style.marginTop=(parseInt(H.marginTop)+I)+"px";break;case"bottom":J.style.marginBottom=(parseInt(H.marginBottom)+I)+"px";break}},300)}function F(){var H=document.getElementById("cookie-bar").clientHeight;if(D("top")){var I=parseInt(document.getElementsByTagName("body")[0].style.marginTop);document.getElementsByTagName("body")[0].style.marginTop=I-H+"px"}else{var G=parseInt(document.getElementsByTagName("body")[0].style.marginBottom);document.getElementsByTagName("body")[0].style.marginBottom=G-H+"px"}}function D(G){var H=t.split(G+"=");if(H[1]){return H[1].split(/[&?]+/)[0]}else{return false}}function n(){c.addEventListener("click",function(){u("cookiebar","CookieAllowed");F();d(w,250);d(p,250);if(D("refreshPage")){window.location.reload()}});B.addEventListener("click",function(){var I=z.textContent.trim();var J=window.confirm(I);if(J===true){k();u("cookiebar","CookieDisallowed");F();d(w,250);d(p,250)}});b.addEventListener("click",function(){x(w,250)});h.addEventListener("click",function(){d(w,250)});if(D("scrolling")){var H=document.body.getBoundingClientRect().top;var G=false;window.addEventListener("scroll",function(){if(G===false){if(document.body.getBoundingClientRect().top-H>250||document.body.getBoundingClientRect().top-H<-250){u("cookiebar","CookieAllowed");F();d(w,250);d(p,250);G=true;if(D("refreshPage")){window.location.reload()}}}})}}}document.addEventListener("DOMContentLoaded",function(){setupCookieBar()});
|