-
Notifications
You must be signed in to change notification settings - Fork 0
/
novaconsent.min.js
1 lines (1 loc) · 1.87 KB
/
novaconsent.min.js
1
function novaConsentObj(){var config={cookieName:"novaConsent",cookieTimeout:365,infoText:"We only use technically necessary cookies.",acceptButtonText:"Okay",moreInfo:"",SameSite:"Strict"};setConfig=function(value){Object.keys(value).forEach(item=>{config[item]=value[item]})};consentHtml=function(){return '<div class="novaConsentContainer" id="novaConsentContainer"><div class="novaConsentInfo">'+config.infoText+' '+config.moreInfo+'</div><div class="novaConsentButton"><a onClick="novaConsent.save();">'+config.acceptButtonText+'</a></div></div>'};function setCookie(value){var date=new Date();date.setTime(date.getTime()+(config.cookieTimeout*24*60*60*1000));var expires=date.toUTCString();var value=JSON.stringify(value);document.cookie=config.cookieName+"="+value+"; expires="+expires+"; path=/; SameSite="+config.SameSite+"; "}function getCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i+=1){var c=ca[i];while(c.charAt(0)==' '){c=c.substring(1,c.length)}if(c.indexOf(nameEQ)==0){return c.substring(nameEQ.length,c.length)}}return null}function checkConsentStatus(){var value=getCookie(config.cookieName);return JSON.parse(value)}this.perform=function(){if(typeof novaConsentConfig!=="undefined"){setConfig(novaConsentConfig)}var result=checkConsentStatus();if(result){}else{this.show()}};this.save=function(analytics,marketing){var value={"consent_shown":Date.now(),"technical":"accepted","analytics":"denied","marketing":"denied"};if(analytics){value.analytics="accepted"}if(marketing){value.marketing="accepted"}setCookie(value);this.hide()};this.show=function(){document.body.innerHTML+=consentHtml()};this.hide=function(){let container=document.querySelector("#novaConsentContainer");container.style.setProperty('opacity','0');setTimeout(()=>container.style.setProperty('display','none'),200)}}var novaConsent=new novaConsentObj();novaConsent.perform();