-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookiesettings.js
212 lines (166 loc) · 7.01 KB
/
cookiesettings.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
let currentLanguage = 'en';
function updateConsentText() {
const texts = languageData[currentLanguage];
const cookieMessageDiv = document.getElementById('RMcookieMessage');
// Update the text while keeping the link
cookieMessageDiv.innerHTML = texts.message + ' <a href="https://rastmobile.com/gizlilik-politikasi/" target="_blank">' + texts.moreInfo + '</a>';
// Update other elements
document.getElementById('RMacceptButton').textContent = texts.accept;
document.getElementById('RMrejectButton').textContent = texts.reject;
document.getElementById('RMsettingsButton').textContent = texts.settings;
document.getElementById('RMCookieModalTitle').textContent = texts.cookieModalTitle;
// Continue updating other elements as necessary
}
function setLanguage(lang) {
if (languageData[lang]) {
currentLanguage = lang;
updateConsentText();
}
}
document.addEventListener('DOMContentLoaded', function () {
RMGenerateCookieCategoryList();
RMCheckCookieConsent();
});
function RMGenerateCookieCategoryList() {
const categoryListContainer = document.getElementById('RMcookieCategoryList');
categoryListContainer.innerHTML = '';
// Create a table
const table = document.createElement('table');
categoryListContainer.appendChild(table);
// Add table header
const thead = document.createElement('thead');
table.appendChild(thead);
const headerRow = document.createElement('tr');
thead.appendChild(headerRow);
const texts = languageData[currentLanguage];
[texts.scriptName, texts.scriptDescription, texts.scriptCategory, texts.scriptActions].forEach(text => {
const th = document.createElement('th');
th.textContent = text;
headerRow.appendChild(th);
});
// Add table body
const tbody = document.createElement('tbody');
table.appendChild(tbody);
document.querySelectorAll('script[data-rastmobile-cookiecategory]').forEach(script => {
const tr = document.createElement('tr');
tbody.appendChild(tr);
// Script Name
const tdName = document.createElement('td');
tdName.textContent = script.getAttribute('data-scriptname') || 'Unnamed Script';
tr.appendChild(tdName);
// Script Description
const tdDescription = document.createElement('td');
tdDescription.textContent = script.getAttribute('data-scriptdescription') || 'No description provided';
tr.appendChild(tdDescription);
// Cookie Category
const tdCategory = document.createElement('td');
tdCategory.textContent = script.getAttribute('data-rastmobile-cookiecategory');
tr.appendChild(tdCategory);
// Actions (Accept/Reject Buttons)
const tdActions = document.createElement('td');
tr.appendChild(tdActions);
const acceptButton = document.createElement('button');
acceptButton.textContent = 'Accept';
acceptButton.onclick = function () { RMAcceptCookies(script.getAttribute('data-rastmobile-cookiecategory')); };
tdActions.appendChild(acceptButton);
const rejectButton = document.createElement('button');
rejectButton.textContent = 'Reject';
rejectButton.onclick = function () { RMRejectCookies(script.getAttribute('data-rastmobile-cookiecategory')); };
tdActions.appendChild(rejectButton);
});
}
function createCategoryHeader(category) {
const header = document.createElement('h4');
header.textContent = `Category: ${category}`;
return header;
}
function createScriptDetails(script) {
const scriptName = script.getAttribute('data-scriptname') || 'Unnamed Script';
const scriptUrl = script.getAttribute('data-scripturl') || 'No URL provided';
const scriptDetails = document.createElement('p');
scriptDetails.textContent = `Script: ${scriptName}, URL: ${scriptUrl}`;
return scriptDetails;
}
function createCategoryButtons(category) {
const buttonContainer = document.createElement('div');
const acceptButton = document.createElement('button');
acceptButton.textContent = 'Accept';
acceptButton.className = 'RM-accept-btn';
acceptButton.onclick = function () { RMAcceptCookies(category); };
buttonContainer.appendChild(acceptButton);
const rejectButton = document.createElement('button');
rejectButton.textContent = 'Reject';
rejectButton.className = 'RM-reject-btn';
rejectButton.onclick = function () { RMRejectCookies(category); };
buttonContainer.appendChild(rejectButton);
return buttonContainer;
}
function RMAcceptCookies(category) {
localStorage.setItem(`RM_${category}_cookie`, 'true');
RMCheckCookieConsent();
}
function RMRejectCookies(category) {
localStorage.setItem(`RM_${category}_cookie`, 'false');
RMCheckCookieConsent();
}
function RMAcceptAllCookies() {
const categories = new Set();
document.querySelectorAll('script[data-rastmobile-cookiecategory]').forEach(script => {
categories.add(script.getAttribute('data-rastmobile-cookiecategory'));
});
categories.forEach(category => {
localStorage.setItem(`RM_${category}_cookie`, 'true');
});
RMCheckCookieConsent();
closeCookieSettingsModal(); // Optionally close the modal after action
}
function RMRejectAllCookies() {
const categories = new Set();
document.querySelectorAll('script[data-rastmobile-cookiecategory]').forEach(script => {
categories.add(script.getAttribute('data-rastmobile-cookiecategory'));
});
categories.forEach(category => {
localStorage.setItem(`RM_${category}_cookie`, 'false');
});
RMCheckCookieConsent();
closeCookieSettingsModal(); // Optionally close the modal after action
}
function RMCheckCookieConsent() {
const categories = document.querySelectorAll('script[data-rastmobile-cookiecategory]');
let allConsented = categories.length > 0; // Assume true only if categories exist
categories.forEach(script => {
const category = script.getAttribute('data-rastmobile-cookiecategory');
if (localStorage.getItem(`RM_${category}_cookie`) !== 'true') {
allConsented = false;
}
});
if (!allConsented) {
document.getElementById('RMcookiePermissionContent').style.display = 'flex';
} else {
RMHideCookieBar();
}
}
function RMHideCookieBar() {
const cookieBar = document.getElementById('RMcookiePermissionContent');
if (cookieBar) {
cookieBar.style.display = 'none';
}
}
function openCookieSettings() {
RMGenerateCookieCategoryList(); // Regenerate the list every time the modal is opened
const modal = document.getElementById('RMcookieSettingsModal');
if (modal) {
modal.style.display = 'block';
}
}
function closeCookieSettingsModal() {
const modal = document.getElementById('RMcookieSettingsModal');
if (modal) {
modal.style.display = 'none';
}
}
function saveCookieSettings() {
// Implement the logic to save specific cookie settings
console.log("Cookie settings saved");
closeCookieSettingsModal();
}