-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookies.js
68 lines (57 loc) · 2.01 KB
/
cookies.js
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
var language = "de-DE"; // Ändern auf Englisch, wenn funktioniert
var languageune1 = null;
var languageune = null;
// Funktion zum Abrufen der Sprache und Zustimmung
function getLanguageAndConsentintern() {
var name = "language=";
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
if (cookie.indexOf(name) === 0) {
var cookieValue = cookie.substring(name.length, cookie.length);
var cookieData = cookieValue.split('&');
var languageune = cookieData[0];
var consent = cookieData[1].split('=')[1];
if (languageune === null) {
languageune1 = "de-DE"; // Ändern auf Englisch, wenn funktioniert
}
return {
languageune1: languageune1,
consent: consent === "true"
};
}
}
if (languageune1 === null) {
language = "de-DE"; // Ändern auf Englisch, wenn funktioniert
} else {
language = languageune1;
}
return {
language: language,
consent: false // Set the default consent to false if no cookies are found
};
}
function setLanguageCookie(language) {
var languageAndConsent = getLanguageAndConsentintern();
if (languageAndConsent) {
var consent = languageAndConsent.consent; // Declare the 'consent' variable here
if (consent) {
var expirationDate = new Date();
expirationDate.setFullYear(expirationDate.getFullYear() + 1);
var cookieValue = "language=" + language + "&cookiesAccepted=true";
document.cookie = cookieValue + "; expires=" + expirationDate.toUTCString() + "; path=/";
}
}
}
// Beispiel für die Verwendung:
function getlngandcons() {
var languageAndConsent = getLanguageAndConsentintern();
if (languageAndConsent) {
var language = languageAndConsent.language;
var consent = languageAndConsent.consent;
console.log("Gespeicherte Sprache: " + language);
console.log("Cookies akzeptiert: " + consent);
} else {
console.log("Keine gespeicherten Daten gefunden");
}
}