File size: 2,836 Bytes
0a84888
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!-- START CUSTOM CODE -->
<!-- 
n8n's cookie consent handling
Ensures cookie consent applies across all .n8n.io properties
-->
<script>
// If the user has accepted cookies, set the n8n-consent cookie
// This means if they then go to the main website, they won't be prompted again
let docsConsent = __md_get("__consent")
let d = new Date();
d.setTime(d.getTime() + 5 * 24 * 60 * 60 * 1000);
let n8nCookie = {'consent': true};
// When user clicks Accept on the consent form, page reloads and this sets
// DEBUG TIP: If it breaks, first thing to do is check the page reload is still happening
if (docsConsent && docsConsent.analytics === true) {
  document.cookie = `n8n-consent=${JSON.stringify(n8nCookie)};expires=${d.toUTCString()};path=/;domain=.n8n.io`;
}

// If the user already has the n8n-consent cookie, accept cookies in docs as well
let getn8nCookie = getCookie("n8n-consent");
if(getn8nCookie) {
  var parsedn8nCookie = JSON.parse(getn8nCookie);
}
if(parsedn8nCookie && parsedn8nCookie.consent === true) {
	// Note that Material uses local storage to remember cookie settings
	__md_set("__consent", {"analytics": true});
}

// Function to help with extracting cookies by name
function getCookie(cname) {
  let name = cname + "=";
  let decodedCookie = decodeURIComponent(document.cookie);
  let ca = decodedCookie.split(';');
  for(let i = 0; i <ca.length; i++) {
    let c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}
</script>
<!-- END CUSTOM CODE -->

<!-- User-preference: consent -->
<script>
  var consent = __md_get("__consent")
  if (consent) {
    for (var input of document.forms.consent.elements)
      if (input.name)
        input.checked = consent[input.name] || false

  /* Show consent with a small delay, but not if browsing locally */
  } else if (location.protocol !== "file:") {
    setTimeout(function() {
      var el = document.querySelector("[data-md-component=consent]")
      el.hidden = false
    }, 250)
  }

  /* Intercept submission of consent form */
  var form = document.forms.consent
  for (var action of ["submit", "reset"])
    form.addEventListener(action, function(ev) {
      ev.preventDefault()

      /* Reject all cookies */
      if (ev.type === "reset")
        for (var input of document.forms.consent.elements)
          if (input.name)
            input.checked = false

      /* Grab and serialize form data */
      console.log(new FormData(form))
      __md_set("__consent", Object.fromEntries(
        Array.from(new FormData(form).keys())
          .map(function(key) { return [key, true] })
      ))

      /* Remove anchor to omit consent from reappearing and reload */
      location.hash = '';
      location.reload()
    })
</script>