diff --git a/CHANGELOG.md b/CHANGELOG.md index e13d168..aaaabc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# v0.1.14 +## 04/05/2024 +1. [](#improved) + * Add the "SameSite" attribute to "Lax" for the "cookieconsent_categories", "cookieconsent_onscroll_scripts" and "cookieconsent_scripts" cookies to comply with Firefox warnings and ensure consistent behavior. + # v0.1.13 ## 04/04/2024 1. [](#improved) @@ -32,7 +37,7 @@ # v0.1.5 ## 02/02/2022 1. [](#new) - * add pull requests from git hub to solve bugs + * add pull requests from github to solve bugs # v0.1.4 ## 12/12/2021 diff --git a/assets/js/tecart-cookie-manager.js b/assets/js/tecart-cookie-manager.js index 6a403ef..1ae9026 100644 --- a/assets/js/tecart-cookie-manager.js +++ b/assets/js/tecart-cookie-manager.js @@ -168,7 +168,7 @@ class TecartCookieBanner{ } const expires = this.cookieExpireDate(); const json_string = JSON.stringify(cookieConsentCategoriesArray); - document.cookie = 'cookieconsent_categories=' + json_string + ';' + expires + ';path=/'; + document.cookie = 'cookieconsent_categories=' + json_string + ';' + expires + ';path=/; SameSite=Lax;'; } /** @@ -180,7 +180,7 @@ class TecartCookieBanner{ } const expires = this.cookieExpireDate(); const json_string = JSON.stringify(cookieConsentScriptsArray); - document.cookie = 'cookieconsent_scripts=' + json_string + ';' + expires + ';path=/'; + document.cookie = 'cookieconsent_scripts=' + json_string + ';' + expires + ';path=/; SameSite=Lax;'; } /** @@ -192,7 +192,7 @@ class TecartCookieBanner{ } const expires = this.cookieExpireDate(); const json_string = JSON.stringify(cookieConsentOnScrollScriptsArray); - document.cookie = 'cookieconsent_onscroll_scripts=' + json_string + ';' + expires + ';path=/'; + document.cookie = 'cookieconsent_onscroll_scripts=' + json_string + ';' + expires + ';path=/; SameSite=Lax;'; } /** @@ -612,7 +612,6 @@ class TecartCookieBanner{ tabSaveSettingsLayout = this.cookieBannerCategoriesData.categories_save_layout; } - const tabs = '
' + tabSection+ '
' + diff --git a/assets/js/tecart-cookie-manager.min.js b/assets/js/tecart-cookie-manager.min.js index 62c3fb0..c54aa69 100644 --- a/assets/js/tecart-cookie-manager.min.js +++ b/assets/js/tecart-cookie-manager.min.js @@ -1 +1 @@ -class TecartCookieBanner{constructor(e,t,o,i){this.cookieBannerData=e,this.cookieBannerScripts=t,this.cookieBannerCategories=o,this.cookieBannerCategoriesData=i,null==this.cookieBannerScripts&&(this.cookieBannerScripts=[]),null==this.cookieBannerCategories&&(this.cookieBannerCategories=[]),null==this.cookieBannerCategoriesData&&(this.cookieBannerCategoriesData=[]),null==this.cookieConsentCategoriesArray&&(this.cookieConsentCategoriesArray=new Map),null==this.cookieConsentScriptsArray&&(this.cookieConsentScriptsArray=new Map),null==this.cookieConsentOnScrollScriptsArray&&(this.cookieConsentOnScrollScriptsArray=new Map),this.cookieConsent=this.getCookieByName("cookieconsent_status"),this.cookieConsentScripts=this.getCookieByName("cookieconsent_scripts"),this.cookieConsentCategories=this.getCookieByName("cookieconsent_categories"),this.cookieConsentOnScrollScripts=this.getCookieByName("cookieconsent_onscroll_scripts"),this.cookieConsentScrolled=this.getCookieByName("cookieconsent_scrolled")}init(){let e="";"activated"==this.getCookieBannerContent(this.cookieBannerData).buttonSettingsActive&&(e=''+this.getCookieBannerContent(this.cookieBannerData).settings+"");let t="";"activated"==this.getCookieBannerContent(this.cookieBannerData).buttonDenyActive&&(t=''+this.getCookieBannerContent(this.cookieBannerData).deny+"");const o={position:"bottom-left",type:"opt-in",palette:{popup:{background:"#f6f9fc",text:"#1e2022",border:"#1e2022"},button:{background:"#fff",text:"#5a5f69",border:"#5a5f69"}},layout:"tecart-cookie-banner",layouts:{"tecart-cookie-banner":'"},revokable:!0,animateRevokable:!0,revokeBtn:'
'+this.getCookieBannerContent(this.cookieBannerData).revoke+"
",onStatusChange:function(e,t){const o=this.hasConsented(),i=new TecartCookieBanner(this.cookieBannerData,this.cookieBannerScripts,this.cookieBannerCategories);o?i.allowAllCookies():!1===o?i.denyAllCookies():i.allowSettingsCookies()},onRevokeChoice:function(e){}};window.cookieconsent.initialise(o),"dismiss"===this.cookieConsent?this.createScriptCode(this.cookieConsentScripts):(this.setCookieConsentCategoriesArray(),this.setCookieConsentScriptsArray()),this.removeSettingsModal(),this.createSettingsModal(this.cookieConsent)}allowAllCookies(){const e=this.cookieExpireDate();document.cookie="cookieconsent_status=allow;"+e+";path=/",console.log("All scripts for this website have been activated in this browser."),window.location.reload()}denyAllCookies(){this.deleteAllCookies(),this.removeCodeTags();const e=this.cookieExpireDate();document.cookie="cookieconsent_status=deny;"+e+";path=/",console.log("All scripts for this website have been deactivated in this browser."),window.location.reload()}allowSettingsCookies(){const e=this.cookieExpireDate();document.cookie="cookieconsent_status=dismiss;"+e+";path=/",console.log("All scripts for this website have set like in settings in this browser.")}setScrolledCookie(){const e=this.cookieExpireDate();document.cookie="cookieconsent_scrolled=scrolled;"+e+";path=/",console.log("Page was scrolled.")}setConsentCategoriesToCookie(e){e instanceof Map&&(e=Array.from(e));const t=this.cookieExpireDate(),o=JSON.stringify(e);document.cookie="cookieconsent_categories="+o+";"+t+";path=/"}setConsentScriptsToCookie(e){e instanceof Map&&(e=Array.from(e));const t=this.cookieExpireDate(),o=JSON.stringify(e);document.cookie="cookieconsent_scripts="+o+";"+t+";path=/"}setConsentOnScrollScriptsToCookie(e){e instanceof Map&&(e=Array.from(e));const t=this.cookieExpireDate(),o=JSON.stringify(e);document.cookie="cookieconsent_onscroll_scripts="+o+";"+t+";path=/"}cookieExpireDate(){const e=new Date;e.setTime(e.getTime()+31536e6);return"expires="+e.toUTCString()}deleteAllCookies(){const e=document.cookie.split("; ");for(let t=0;t0;){const i=encodeURIComponent(e[t].split(";")[0].split("=")[0])+"=; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain="+o.join(".")+" ;path=",n=location.pathname.split("/");for(document.cookie=i+"/";n.length>0;)document.cookie=i+n.join("/"),n.pop();o.shift()}}window.localStorage.clear(),console.log("all cookies cleared")}getCookieByName(e){const t=document.cookie.match("(^|[^;]+)\\s*"+e+"\\s*=\\s*([^;]+)");return t?t.pop():""}deleteCookieByName(e){document.cookie=e+"=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;",console.log(e+" cookie deletetd")}setCookieConsentCategoriesArray(){let e;const t=this.cookieBannerCategories;if(t.length>0)for(let o=0;o0)for(let o=0;o0&&o.length>0)for(let e=0;e0&&""!==n)for(let e=0;e0){const i=e.code_title,n=e.code_position,s=e.code_tag,c=e.code_load_with_timeout,a=e.code_load_with_timeout_time,r=e.code_load_on_scroll,l=(e.code_load_on_scroll_percent,"code_load_on_pages"in e?e.code_load_on_pages:[]),d=window.location.pathname;let k=!0;l.length>0&&-1===l.indexOf(d)&&(k=!1);let h="";if("noscript"===s?h=document.createElement("noscript"):(h=document.createElement("script"),h.setAttribute("type","text/javascript")),h.setAttribute("data-title",o.trim()),h.setAttribute("data-tcb",t),h.setAttribute("data-position",n),h.innerHTML=i.trim(),k)if("scrolled"===this.cookieConsentScrolled){const e=this;"1"===c?setTimeout((function(){e.addScriptTagToDOM(n,h)}),a):e.addScriptTagToDOM(n,h)}else if("1"===r)this.cookieConsentOnScrollScriptsArray.set(t,{allowed:!0});else if("1"===c&&"0"===r){const e=this;setTimeout((function(){e.addScriptTagToDOM(n,h)}),a)}else this.addScriptTagToDOM(n,h)}}addScriptTagToDOM(e,t){"head"===e?document.head.append(t):"body-top"===e?document.body.prepend(t):document.body.appendChild(t)}removeCodeTagByTitle(e){if(""!==e){const t=document.querySelectorAll("[data-tcb]");for(const o in t)t.hasOwnProperty(o)&&t[o].getAttribute("data-tcb")===e&&t[o].remove()}}removeCodeTags(){const e=document.querySelectorAll("[data-tcb]");for(const t in e)e.hasOwnProperty(t)&&e[t].remove()}createSettingsModal(e=""){const t='";document.body.insertAdjacentHTML("beforeend",t)}removeSettingsModal(){const e=document.getElementById("tcb-settings-modal");null!==e&&e.remove()}createSettingsModalTabs(e=""){let t="",o="";const i=this.cookieBannerCategories;if(!(i.length>0))return this.getCookieBannerContent(this.cookieBannerData).settingsEmpty;for(let n=0;n0&&(o=this.createSettingsModalTabsScripts(i[n].category_title,e));const s=i[n].category_text?i[n].category_text:"",c=i[n].category_title?i[n].category_title:"",a=encodeURIComponent(c);let r="";"allow"===e?r="checked":this.cookieConsentCategories.length>0?!0===this.cookieConsentCategories.includes(a)&&(r="checked"):"activated"===i[n].category_cookies&&(r="checked");let l="";"activated"===i[n].category_cookies&&(l='');t+='

'+c+"

"+l+"

"+s+"

"+o+"
"}let n="Save Settings";this.cookieBannerCategoriesData.categories_save_text&&(n=this.cookieBannerCategoriesData.categories_save_text);let s="layout-1";this.cookieBannerCategoriesData.categories_save_layout&&(s=this.cookieBannerCategoriesData.categories_save_layout);return'
'+t+'
"}createSettingsModalTabsScripts(e="",t=""){let o="";if(""!==e&&this.cookieBannerScripts.length>0){const i=this.getElementByValue(this.cookieBannerScripts,"script_category",e);if(i.length>0){o+="
    ";for(let e=0;e0?!0===this.cookieConsentScripts.includes(s)&&(c="checked"):"activated"===i[e].script_cookies_standard&&(c="checked");let a="",r="",l="tcbCookieScripts";"0"===i[e].script_cookies&&(a='disabled="disabled"',r="disabled",l="tcbDisabledCookieScripts"),o+='
  • '+n+'
    '+i[e].script_text+"
  • "}o+="
"}}return o}onCheckboxSettings(){this.deleteCookieByName("cookieconsent_scripts"),this.deleteCookieByName("cookieconsent_categories"),this.deleteAllCookies();let e=[],t=[];if(this.cookieConsentScriptsArray=new Map,e=Array.from(document.querySelectorAll("input[name=tcbCookieScripts], input[name=tcbDisabledCookieScripts]")).filter((e=>e.checked)).map((e=>e.value)),e.length>0)for(let t=0;te.checked)).map((e=>e.value)),t.length>0)for(let e=0;e'+this.getCookieBannerContent(this.cookieBannerData).settings+""}let buttonDeny="";if(this.getCookieBannerContent(this.cookieBannerData).buttonDenyActive=="activated"){buttonDeny=''+this.getCookieBannerContent(this.cookieBannerData).deny+""}const cookieconsentInitialse={position:"bottom-left",type:"opt-in",palette:{popup:{background:"#f6f9fc",text:"#1e2022",border:"#1e2022"},button:{background:"#fff",text:"#5a5f69",border:"#5a5f69"}},layout:"tecart-cookie-banner",layouts:{"tecart-cookie-banner":'"},revokable:true,animateRevokable:true,revokeBtn:'
'+this.getCookieBannerContent(this.cookieBannerData).revoke+"
",onStatusChange:function(status,chosenBefore){const didConsent=this.hasConsented();const tcb=new TecartCookieBanner(this.cookieBannerData,this.cookieBannerScripts,this.cookieBannerCategories);if(didConsent){tcb.allowAllCookies()}else if(didConsent===false){tcb.denyAllCookies()}else{tcb.allowSettingsCookies()}},onRevokeChoice:function(status){}};window.cookieconsent.initialise(cookieconsentInitialse);if(this.cookieConsent==="dismiss"){this.createScriptCode(this.cookieConsentScripts)}else{this.setCookieConsentCategoriesArray();this.setCookieConsentScriptsArray()}this.removeSettingsModal();this.createSettingsModal(this.cookieConsent)}allowAllCookies(){const expires=this.cookieExpireDate();document.cookie="cookieconsent_status=allow;"+expires+";path=/";console.log("All scripts for this website have been activated in this browser.");window.location.reload()}denyAllCookies(){this.deleteAllCookies();this.removeCodeTags();const expires=this.cookieExpireDate();document.cookie="cookieconsent_status=deny;"+expires+";path=/";console.log("All scripts for this website have been deactivated in this browser.");window.location.reload()}allowSettingsCookies(){const expires=this.cookieExpireDate();document.cookie="cookieconsent_status=dismiss;"+expires+";path=/";console.log("All scripts for this website have set like in settings in this browser.")}setScrolledCookie(){const expires=this.cookieExpireDate();document.cookie="cookieconsent_scrolled=scrolled;"+expires+";path=/";console.log("Page was scrolled.")}setConsentCategoriesToCookie(cookieConsentCategoriesArray){if(cookieConsentCategoriesArray instanceof Map){cookieConsentCategoriesArray=Array.from(cookieConsentCategoriesArray)}const expires=this.cookieExpireDate();const json_string=JSON.stringify(cookieConsentCategoriesArray);document.cookie="cookieconsent_categories="+json_string+";"+expires+";path=/; SameSite=Lax;"}setConsentScriptsToCookie(cookieConsentScriptsArray){if(cookieConsentScriptsArray instanceof Map){cookieConsentScriptsArray=Array.from(cookieConsentScriptsArray)}const expires=this.cookieExpireDate();const json_string=JSON.stringify(cookieConsentScriptsArray);document.cookie="cookieconsent_scripts="+json_string+";"+expires+";path=/; SameSite=Lax;"}setConsentOnScrollScriptsToCookie(cookieConsentOnScrollScriptsArray){if(cookieConsentOnScrollScriptsArray instanceof Map){cookieConsentOnScrollScriptsArray=Array.from(cookieConsentOnScrollScriptsArray)}const expires=this.cookieExpireDate();const json_string=JSON.stringify(cookieConsentOnScrollScriptsArray);document.cookie="cookieconsent_onscroll_scripts="+json_string+";"+expires+";path=/; SameSite=Lax;"}cookieExpireDate(){const d=new Date;d.setTime(d.getTime()+365*24*60*60*1e3);const expires="expires="+d.toUTCString();return expires}deleteAllCookies(){const cookies=document.cookie.split("; ");for(let c=0;c0){const cookieBase=encodeURIComponent(cookies[c].split(";")[0].split("=")[0])+"=; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain="+d.join(".")+" ;path=";const p=location.pathname.split("/");document.cookie=cookieBase+"/";while(p.length>0){document.cookie=cookieBase+p.join("/");p.pop()}d.shift()}}window.localStorage.clear();console.log("all cookies cleared")}getCookieByName(name){const b=document.cookie.match("(^|[^;]+)\\s*"+name+"\\s*=\\s*([^;]+)");return b?b.pop():""}deleteCookieByName(name){document.cookie=name+"=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";console.log(name+" cookie deletetd")}setCookieConsentCategoriesArray(){let title;const json_data=this.cookieBannerCategories;if(json_data.length>0){for(let i=0;i0){for(let i=0;i0&&scriptArray.length>0){for(let i=0;i0&&cookieScriptTitle!==""){for(let x=0;x0){const codeContent=data.code_title;const codePos=data.code_position;const codeTag=data.code_tag;const codeLoadTimeout=data.code_load_with_timeout;const codeLoadTimeoutTime=data.code_load_with_timeout_time;const codeLoadOnScroll=data.code_load_on_scroll;const codeLoadOnScrollPercent=data.code_load_on_scroll_percent;const codeLoadOnPages="code_load_on_pages"in data?data.code_load_on_pages:[];const currPagePath=window.location.pathname;let pageAllowed=true;if(codeLoadOnPages.length>0&&codeLoadOnPages.indexOf(currPagePath)===-1){pageAllowed=false}let codeItem="";if(codeTag==="noscript"){codeItem=document.createElement("noscript")}else{codeItem=document.createElement("script");codeItem.setAttribute("type","text/javascript")}codeItem.setAttribute("data-title",scriptTitle.trim());codeItem.setAttribute("data-tcb",scriptTitleEncoded);codeItem.setAttribute("data-position",codePos);codeItem.innerHTML=codeContent.trim();if(pageAllowed){if(this.cookieConsentScrolled==="scrolled"){const self=this;if(codeLoadTimeout==="1"){setTimeout(function(){self.addScriptTagToDOM(codePos,codeItem)},codeLoadTimeoutTime)}else{self.addScriptTagToDOM(codePos,codeItem)}}else{if(codeLoadOnScroll==="1"){this.cookieConsentOnScrollScriptsArray.set(scriptTitleEncoded,{allowed:true})}else if(codeLoadTimeout==="1"&&codeLoadOnScroll==="0"){const self=this;setTimeout(function(){self.addScriptTagToDOM(codePos,codeItem)},codeLoadTimeoutTime)}else{this.addScriptTagToDOM(codePos,codeItem)}}}}}addScriptTagToDOM(codePos,codeItem){if(codePos==="head"){document.head.append(codeItem)}else if(codePos==="body-top"){document.body.prepend(codeItem)}else{document.body.appendChild(codeItem)}}removeCodeTagByTitle(dataTitle){if(dataTitle!==""){const tags=document.querySelectorAll("[data-tcb]");for(const i in tags){if(tags.hasOwnProperty(i)){if(tags[i].getAttribute("data-tcb")===dataTitle){tags[i].remove()}}}}}removeCodeTags(){const tags=document.querySelectorAll("[data-tcb]");for(const i in tags){if(tags.hasOwnProperty(i)){tags[i].remove()}}}createSettingsModal(status=""){const settingsModal='";document.body.insertAdjacentHTML("beforeend",settingsModal)}removeSettingsModal(){const modalWindow=document.getElementById("tcb-settings-modal");if(modalWindow!==null){modalWindow.remove()}}createSettingsModalTabs(status=""){let tabSection="";let tabSaveSettings="";let article="";const json_data=this.cookieBannerCategories;if(json_data.length>0){for(let i=0;i0){article=this.createSettingsModalTabsScripts(json_data[i].category_title,status)}const catText=json_data[i].category_text?json_data[i].category_text:"";const catTitle=json_data[i].category_title?json_data[i].category_title:"";const catTitleEncoded=encodeURIComponent(catTitle);let activated="";if(status==="allow"){activated="checked"}else if(this.cookieConsentCategories.length>0){if(this.cookieConsentCategories.includes(catTitleEncoded)===true){activated="checked"}}else{if(json_data[i].category_cookies==="activated"){activated="checked"}}let cat_toggler="";if(json_data[i].category_cookies==="activated"){cat_toggler='"}const checkedTab=i===0?'checked=""':"";tabSection+='
'+'"+'"+"
"+'
'+"

"+catTitle+"

"+cat_toggler+"
"+"

"+catText+"

"+article+"
"+"
"}}else{return this.getCookieBannerContent(this.cookieBannerData).settingsEmpty}let tabSaveSettingsText="Save Settings";if(this.cookieBannerCategoriesData.categories_save_text){tabSaveSettingsText=this.cookieBannerCategoriesData.categories_save_text}let tabSaveSettingsLayout="layout-1";if(this.cookieBannerCategoriesData.categories_save_layout){tabSaveSettingsLayout=this.cookieBannerCategoriesData.categories_save_layout}const tabs='
'+tabSection+"
"+'";return tabs}createSettingsModalTabsScripts(categoryTitle="",status=""){let tabScripts="";if(categoryTitle!==""&&this.cookieBannerScripts.length>0){const tabScriptItems=this.getElementByValue(this.cookieBannerScripts,"script_category",categoryTitle);if(tabScriptItems.length>0){tabScripts+="
    ";for(let x=0;x0){if(this.cookieConsentScripts.includes(scriptTitleEncoded)===true){activated="checked"}}else{if(tabScriptItems[x].script_cookies_standard==="activated"){activated="checked"}}let readonly="";let readonlyClass="";let name="tcbCookieScripts";if(tabScriptItems[x].script_cookies==="0"){readonly='disabled="disabled"';readonlyClass="disabled";name="tcbDisabledCookieScripts"}tabScripts+="
  • "+'
    '+scriptTitle+"
    "+'"+'
    '+tabScriptItems[x].script_text+"
    "+"
  • "}tabScripts+="
"}}return tabScripts}onCheckboxSettings(){this.deleteCookieByName("cookieconsent_scripts");this.deleteCookieByName("cookieconsent_categories");this.deleteAllCookies();let selectedScripts=[];let selectedCats=[];let catScripts=[];this.cookieConsentScriptsArray=new Map;selectedScripts=Array.from(document.querySelectorAll("input[name=tcbCookieScripts], input[name=tcbDisabledCookieScripts]")).filter(checkbox=>checkbox.checked).map(checkbox=>checkbox.value);if(selectedScripts.length>0){for(let i=0;icheckbox.checked).map(checkbox=>checkbox.value);if(selectedCats.length>0){for(let i=0;i