From aaba8e63c2868fd4f58d58559715441326a9e39a Mon Sep 17 00:00:00 2001 From: "Felix A. Schultz" Date: Wed, 2 Oct 2024 12:34:03 +0200 Subject: [PATCH] Refactor message handling in cb.js to improve event listener logic and enhance cookie information sending --- cb.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/cb.js b/cb.js index 956229e..5030df3 100644 --- a/cb.js +++ b/cb.js @@ -771,30 +771,31 @@ window.addEventListener("load", function () { if (document.querySelector("[name=intastellar-solutions-sharinglibrary-iframe]") != null) { const intastellariframe = document.querySelector("[name=intastellar-solutions-sharinglibrary-iframe]"); if (window?.INTA?.settings?.partnerDomain) { - window.addEventListener("message", function (event) { + function sendCookieInformation(event) { if (event.origin !== "https://consents.cdn.intastellarsolutions.com") return; if (event.data === "ready" && intaConsentsObjectVariable.sharingDomains.length > 0 && intaConsentsObjectVariable.sharingDomains.includes(window.location.host)) { intastellariframe.contentWindow.postMessage(intaConsentsObjectVariable, "https://consents.cdn.intastellarsolutions.com"); + + window.removeEventListener("message", sendCookieInformation); } + } + window.addEventListener("message", sendCookieInformation); + + window.addEventListener("message", function (event) { + if (event.origin !== "https://consents.cdn.intastellarsolutions.com") return; + + + console.log(event); + /* if (event.data.cookieSharing !== undefined || event.data.cookieSharing !== null) { + const intastellarUserGivingConsents = event.data.cookieSharing; + console.log(intastellarUserGivingConsents); + document.cookie = + int_hideCookieBannerName + "=__inta1." + encodeIntaConsentsObject(intastellarUserGivingConsents, randomIntFromInterval(20, 34)) + "; expires=" + cookieLifeTime + + "; path=/; " + + intCookieDomain + + ""; + } */ }); - setTimeout(() => { - - window.addEventListener("message", function (event) { - if (event.origin !== "https://consents.cdn.intastellarsolutions.com") return; - - - console.log(event); - /* if (event.data.cookieSharing !== undefined || event.data.cookieSharing !== null) { - const intastellarUserGivingConsents = event.data.cookieSharing; - console.log(intastellarUserGivingConsents); - document.cookie = - int_hideCookieBannerName + "=__inta1." + encodeIntaConsentsObject(intastellarUserGivingConsents, randomIntFromInterval(20, 34)) + "; expires=" + cookieLifeTime + - "; path=/; " + - intCookieDomain + - ""; - } */ - }); - }, 1000); } }