mirror of
https://github.com/n8n-io/n8n-docs.git
synced 2025-11-20 17:48:34 +00:00
88 lines
2.8 KiB
HTML
88 lines
2.8 KiB
HTML
<!-- 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>
|