-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrivacyPolicy.js
299 lines (250 loc) · 9.5 KB
/
PrivacyPolicy.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*jshint esversion: 6 */
/*
DSGVO compliant OPT-IN and OPT-OUT way!
Style: assets/css/privacypolicy.css
@author Marcel Kempf (marcel@familie-kempf.net)
@date 09/01/2019
Copyright (C) 2019 Marcel Kempf - All Rights Reserved
usage:
<script src='' data-PPName='Google' data-PPSrc='https://www.googlemaps.de' data-PPInfo='/datenschutz#Google' data-PPAllowed='false'></script>
<link data-PPSrc='https://www.googlemaps.de'>
<iframe data-PPSrc='https://www.googlemaps.de'></iframe>
<span data-PPSrc='https://www.googlemaps.de'></span> //initalize into privacy policy, but don't implement into current page
*/
/**********************************************
Plugin Management
**********************************************/
var Third_Parties = (function() {
let sitePlugins = [];
let thirdParties = {};
(function init() {
sitePlugins = document.querySelectorAll('[data-PPSrc]');
})();
/*
Look for PrivacyPolicy instance in localStorage
*/
function storageAlreadyExists() {
return window.localStorage.getItem('PrivacyPolicy') != null ? true : false;
}
function setPlugin(dataset) {
if(!isOldPlugin(dataset)) {
if(isPluginNotAccepted(dataset)) dataset.ppallowed = "null";
thirdParties = Object.assign(thirdParties, { [dataset.ppname] : dataset });
}
}
function getStorage() {
return JSON.parse(window.localStorage.getItem('PrivacyPolicy')) || [];
}
function getPlugin(name) {
return thirdParties[name];
}
function getPluginFromStorage(name) {
return getStorage[name];
}
function isPluginNotAccepted(dataset) {
return dataset.ppallowed == "null" || dataset.ppallowed == undefined;
}
function isOldPlugin(pluginDataset) {
let activePlugins = [...sitePlugins].map((sp) => sp.dataset)
.filter((dataset) => dataset.ppname == pluginDataset.ppname);
return (activePlugins.length == 0 ? true : false);
}
return {
/*
Returns every plugin of the current webpage
*/
getPlugins: function() {
return thirdParties;
},
/*
Returns every plugin of the current webpage
*/
getSitePlugins: function() {
return sitePlugins;
},
/*
Activates all plugins on the site based on the storage settings
*/
activatePlugins: function() {
sitePlugins.forEach(elem => {
const data = getPlugin(elem.dataset.ppname);
if(data != undefined) {
if(data.ppallowed == "true") {
elem.dataset.ppallowed = true;
if(elem.tagName != "span")
if(elem.tagName == "link")
elem.href = elem.dataset.ppsrc;
else
elem.src = elem.dataset.ppsrc;
} else {
elem.dataset.ppallowed = false;
if(elem.tagName != "span")
if(elem.tagName == "link")
elem.href = '';
else
elem.src = '';
}
} else if(elem.tagName != "span" && elem.dataset.ppallowed == "true")
elem.src = elem.dataset.ppsrc;
});
},
/*
Load external script from localStorage
Undefined plugins get added to the varible thirdParties
*/
loadStorage: function() {
if(storageAlreadyExists()) {
Object.getOwnPropertyNames(getStorage()).forEach((keys) => { setPlugin(getStorage()[keys]); });
} else {
this.saveToStorage();
this.loadStorage();
}
},
/*
Load external script from localStorage
Undefined plugins get added to the varible thirdParties
*/
initalizeNewPlugins: function() {
let newPlugins = [...sitePlugins].map((sp) => sp.dataset)
.filter((dataset) => thirdParties[dataset.ppname] == undefined);
for(const plugin of newPlugins)
setPlugin(plugin);
},
/*
Set thirdParties(all external files of current webpage) in localStorage
*/
saveToStorage: function() {
window.localStorage.setItem('PrivacyPolicy', JSON.stringify(this.getPlugins()));
},
/*
Turn on plugin in Third-Party
*/
allow: function(dataset) {
dataset.ppallowed = "true";
setPlugin(dataset);
},
/*
Turn off plugin in Third-Party
*/
disallow: function(dataset) {
dataset.ppallowed = "false";
setPlugin(dataset);
},
/*
Toogle Third-Party state in thirdParties
*/
togglePluginState: function(plName) {
const dataset = Third_Parties.getPlugins()[plName];
if(dataset.ppallowed == "false") dataset.ppallowed = "true";
else dataset.ppallowed = "false";
},
/*
Turn on all plugins in Third-Party
*/
allowAll: function() {
for(const plName in Third_Parties.getPlugins()) {
const dataset = Third_Parties.getPlugins()[plName];
this.allow(dataset);
}
},
/*
TRUE, if not asked for permission external source exists
*/
existsNewThirdParty: function() {
return [...sitePlugins].map((sp) => sp.dataset.ppname)
.filter((name) => thirdParties[name] == undefined).length > 0;
}
};
})();
/**********************************************
PrivacyPolicy
**********************************************/
var PrivacyPolicy = (function() {
const informationText = `<p id='disclamer'>This site uses cookies for analytical purposes and to improve your browsing experience. To learn more, please read our
<a href='/Datenschutz'>privacy policy</a>.
Do you agree to the use of these cookies and the associated processing of your personal data?
</p>
<input type='button' id='settingsPrivacyPolicy' value='Settings'></input>
<input type='button' id='acceptPrivacyPolicy' value='Accept'></input>
<div id='settingsPolicyWindow' class='invinsible'></div>`;
function createSettingsButton() {
let settingsButton = document.getElementById('settingsPrivacyPolicy');
let settingsWindow = document.getElementById('settingsPolicyWindow');
settingsWindow.innerHTML = PrivacyPolicy.listAllPlugins();
settingsButton.addEventListener('click', () => {
settingsWindow.classList.toggle('invinsible');
});
}
function createAcceptButton() {
let acceptButton = document.getElementById('acceptPrivacyPolicy');
acceptButton.addEventListener('click', () => {
Third_Parties.activatePlugins();
Third_Parties.saveToStorage();
document.getElementById('privacyPolicyWindow').classList.add('invinsible');
window.location = window.location;
});
}
return {
createPopUp: function() {
let privacyWindow = document.getElementById('privacyPolicyWindow') ||
(function() {
let con = document.createElement('div');
con.id = 'privacyPolicyWindow';
con.innerHTML = informationText;
document.body.appendChild(con);
createSettingsButton();
createAcceptButton();
document.getElementById('privacyPolicyWindow').classList.add('invinsible');
return con;
})();
privacyWindow.classList.toggle('invinsible');
},
listAllPlugins: function() {
let listedPlugins = '';
for(const pl in Third_Parties.getPlugins()) {
const dataset = Third_Parties.getPlugins()[pl];
const checked = dataset.ppallowed == "true" ? 'checked' : '';
listedPlugins += `<div class='settingsWindowItem'>
<p>${pl}</p>
<a href='${dataset.ppinfo}'>Info</a>
<label class="switch">
<input type="checkbox" ${checked} onClick="Third_Parties.togglePluginState('${pl}')">
<span class="slider round"></span>
</label>
</div><br>`;
}
return listedPlugins;
},
init: function() {
if (typeof(Storage) !== "undefined") {
Third_Parties.loadStorage();
Third_Parties.activatePlugins();
if(Third_Parties.existsNewThirdParty()) {
Third_Parties.initalizeNewPlugins();
Third_Parties.allowAll();
PrivacyPolicy.createPopUp();
}
} else alert("Your browser doesn't support local storage! Update your browser to a compatible HTML5 version!");
}
};
})();
PrivacyPolicy.init();
function loadGMaps() {
var gmegMap, gmegMarker, gmegInfoWindow, gmegLatLng;
google.maps.event.addDomListener(window, "load", function() {
gmegLatLng = new google.maps.LatLng(52.51845, 13.3737497);
gmegMap = new google.maps.Map(document.getElementById("gmeg_map_canvas"), {
zoom: 14,
center: gmegLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
gmegMarker = new google.maps.Marker({
map: gmegMap,
position: gmegLatLng
});
gmegInfoWindow = new google.maps.InfoWindow({
content: '<b>Federal Parliament Berlin</b><br>Platz der Republik 1, 11011 Berlin'
});
gmegInfoWindow.open(gmegMap, gmegMarker);
});
}