-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcookieSharingIframe.html
59 lines (50 loc) · 2.24 KB
/
cookieSharingIframe.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Intastellar Cookie Sharing infos</title>
</head>
<body>
<script>
/* (function() {
"use strict"; */
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(";");
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === " ") {
c = c.substring(1);
}
/* console.log(localStorage.getItem(cname), cname); */
if (c.indexOf(name) === 0 && localStorage.getItem(cname) === null) {
return c.substring(name.length, c.length);
} else if (localStorage.getItem(cname) !== null) {
return localStorage.getItem(cname);
}
}
return "";
}
window.addEventListener("message", (event) => {
const origin = event.origin || event.originalEvent.origin;
const localStorageData = localStorage.getItem("cookieSharing#" + origin.replace("https://", "").replace("http://", "").replace("www.", ""));
const partnerDomains = JSON.parse(localStorage.getItem("cookieSharing#" + origin.replace("https://", "").replace("http://", "").replace("www.", "")));
if (JSON.parse(event.data)) {
if (JSON.parse(event.data).domain) {
localStorage.setItem("cookieSharing#" + JSON.parse(event.data).domain.replace("https://", "").replace("http://", "").replace("www.", ""), event.data);
}
}
if (partnerDomains?.sharingDomains.length > 0 && partnerDomains?.sharingDomains?.includes(origin.replace("https://", "").replace("http://", "").replace("www.", ""))) {
if (event.data === "getConsents") {
const cookie = localStorageData;
window.parent.postMessage(cookie, "*");
}
}
});
window.parent.postMessage("ready", "*");
/* })(); */
</script>
</body>
</html>