PageSourceSearch

https://autogrillpavesi.eu/plugins/system/cookiesck/assets/front.js?ver=3.3.4

js autogrillpavesi.eu collected 2026-10-07 07:23:20 UTC 16,603 bytes, 448 lines download raw bytes

1(function() {
2
3	"use strict";
4
5	var opts;
6
7	var Cookiesck = function (options) {
8		//set default options  
9		var defaults = {
10			lifetime: ''
11			,layout: ''
12			,reload: ''
13		};
14
15		if (!(this instanceof Cookiesck)) return new Cookiesck(options);
16
17		opts = Object.assign(defaults, options);
18
19		initHtml();
20		initInterface();
21		initEvents();
22		initIframes();
23	}
24
25	function initHtml() {
26		// remove the banner from the page if exists
27		let banner = document.getElementById('cookiesck');
28		if (banner) banner.remove();
29
30		// create the banner in the page
31		banner = document.createElement('div');
32		banner.id = 'cookiesck';
33		banner.setAttribute('data-layout', opts.layout);
34		banner.innerHTML = createBannerHtml();
35		document.body.appendChild(banner);
36
37		// create the overlay
38		let overlay = document.createElement('div');
39		overlay.id = 'cookiesck_overlay';
40		document.body.appendChild(overlay);
41
42		// create the overlay
43		let options = document.createElement('div');
44		options.id = 'cookiesck_options';
45		options.innerHTML = '<div class="inner">' + COOKIESCK.TEXT.OPTIONS + '</div>';
46		document.body.appendChild(options);
47	}
48
49	function createBannerHtml() {
50		let html = '<div class="inner">'
51			+ '<span id="cookiesck_text">' + COOKIESCK.TEXT.INFO + '</span>'
52			+ '<span id="cookiesck_buttons">'
53				+ '<a class="cookiesck_button" id="cookiesck_accept">' + COOKIESCK.TEXT.ACCEPT_ALL + '</a>'
54				+ '<a class="cookiesck_button" id="cookiesck_decline">' + COOKIESCK.TEXT.DECLINE_ALL + '</a>'
55				+ '<a class="cookiesck_button" id="cookiesck_settings">' + COOKIESCK.TEXT.SETTINGS + '</a>'
56				+ '<div style="clear:both;"></div>'
57			+ '</div>'
58			
59			+ '</div>';
60
61		return html;
62	}
63
64	function initInterface() {
65		let cookie = readCookie('cookiesck');
66		document.getElementById('cookiesck').style.display = 'none';
67		document.getElementById('cookiesck_overlay').style.display = 'none';
68		// cookies not set, display the bar
69		if(cookie == null) {
70			document.getElementById('cookiesck').style.display = 'block';
71			document.getElementById('cookiesck_overlay').style.display = 'block';
72		} else {
73			COOKIESCK.VALUE = decodeURIComponent(decodeURIComponent(cookie));
74			debug('COOKIESCK.VALUE : ' + COOKIESCK.VALUE);
75		}
76
77		var cookieArray = toObject();
78		let interfac = document.getElementById('cookiesck_interface');
79		let platforms = interfac.querySelectorAll('.cookiesck-platform');
80		debug('platforms :');
81		debug(platforms);
82		platforms.forEach(function(platform) {
83			let platformName = platform.getAttribute('data-platform');
84			let buttons = platform.querySelectorAll('.cookiesck_button');
85
86			buttons.forEach(function(button) {
87				button.onclick = function() {
88					if (this.classList.contains('cookiesck-accept')) {
89						doAction(this, 'accept');
90					} else {
91						doAction(this, 'decline');
92					}
93					interfac.querySelectorAll('.cookiesck-main-buttons .cookiesck_button').forEach(function(btn) { btn.classList.remove('cookiesck-active'); });
94					highlightAllButton();
95				}
96			});
97
98			// set active button
99			if (cookieArray[platformName]) {
100				if (cookieArray[platformName] == 1) {
101					platform.querySelector('.cookiesck-accept').classList.add('cookiesck-active');
102				} else {
103					platform.querySelector('.cookiesck-decline').classList.add('cookiesck-active');
104				}
105			}
106		});
107
108		if (COOKIESCK.VALUE === 'yes') {
109			interfac.querySelectorAll('.cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
110		} else if (COOKIESCK.VALUE === 'no' || COOKIESCK.VALUE === 'null') {
111			interfac.querySelectorAll('.cookiesck-decline').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
112		}
113
114		// force essential to be active
115		if (interfac.querySelector('[data-category="essential"]')) {
116			interfac.querySelectorAll('[data-category="essential"] .cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); }); 
117		}
118
119		highlightAllButton();
120
121		// close the interface
122		interfac.querySelector('.cookiesck-main-close').onclick = function() {
123			updateCookieValue();
124			interfac.style.display = 'none';
125			document.getElementById('cookiesck_options').style.display = 'block';
126			document.getElementById('cookiesck_overlay').style.display = 'none';
127			if (opts.reload === '1') location.reload();
128		}
129	}
130
131	function highlightAllButton() {
132		let interfac = document.getElementById('cookiesck_interface');
133		if (interfac.querySelectorAll('.cookiesck-category .cookiesck-accept').length === interfac.querySelectorAll('.cookiesck-category .cookiesck-accept.cookiesck-active').length) {
134			interfac.querySelectorAll('.cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
135		} else if (interfac.querySelectorAll('.cookiesck-category .cookiesck-decline').length === interfac.querySelectorAll('.cookiesck-category .cookiesck-decline.cookiesck-active').length) {
136			interfac.querySelectorAll('.cookiesck-decline').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
137		}
138	}
139
140	function initEvents() {
141		let acceptButtons = document.querySelectorAll('#cookiesck_accept,.cookiesck-main-buttons .cookiesck-accept');
142		acceptButtons.forEach(function(acceptButton) {
143			acceptButton.onclick = function() {
144				debug('acceptButton.onclick');
145				if (this.classList.contains('cookiesck-accept')) { acceptAll(); }
146				setCookie("cookiesck","yes",COOKIESCK.LIFETIME);
147				if (COOKIESCK.LOG === '1') {
148					// if not unique key has been set, set it now with the session ID
149					if (! readCookie('cookiesckuniquekey')) {
150						setCookie('cookiesckuniquekey', COOKIESCK.UNIQUE_KEY, opts.lifetime);
151					}
152				}
153				doAjax(location.href, 'set_cookieck=1');
154				document.getElementById('cookiesck').classList.add('cookiesck-hide');
155				document.getElementById('cookiesck').style.display = 'none';
156				document.getElementById('cookiesck_options').style.display = 'block';
157				document.getElementById('cookiesck_overlay').style.display = 'none';
158				loadIframes();
159				if (opts.reload === '1' && this.id == 'cookiesck_accept') location.reload();
160			}
161		});
162		let declineButtons = document.querySelectorAll('#cookiesck_decline, .cookiesck-main-buttons .cookiesck-decline');
163		declineButtons.forEach(function(declineButton) {
164			declineButton.onclick = function() {
165				debug('declineButton.onclick');
166				if (this.classList.contains('cookiesck-decline')) { declineAll(); }
167				// remove the cookies for all platforms
168				let interfac = document.getElementById('cookiesck_interface');
169				let categories = interfac.querySelectorAll('.cookiesck-category');
170				categories.forEach(function(category) {
171					let categoryName = category.getAttribute('data-category');
172					if (categoryName !== 'Essential') {
173						let platforms = category.querySelectorAll('.cookiesck-platform');
174						platforms.forEach(function(platform) {
175							let platformName = platform.getAttribute('data-platform');
176							removeCookie(platformName);
177						})
178					}
179				})
180				
181
182				setCookie("cookiesck","no",COOKIESCK.LIFETIME);
183				if (COOKIESCK.LOG === '1') {
184					// if not unique key has been set, set it now with the session ID
185					if (! readCookie('cookiesckuniquekey')) {
186						setCookie('cookiesckuniquekey', COOKIESCK.UNIQUE_KEY, opts.lifetime);
187					}
188				}
189				doAjax(location.href, 'set_cookieck=0');
190				document.getElementById('cookiesck').classList.add('cookiesck-hide');
191				document.getElementById('cookiesck').style.display = 'none';
192				document.getElementById('cookiesck_options').style.display = 'block';
193				document.getElementById('cookiesck_overlay').style.display = 'none';
194			}
195		});
196		document.getElementById('cookiesck_settings').onclick = function(){
197			document.getElementById('cookiesck_interface').style.display = 'block';
198			document.getElementById('cookiesck').style.display = 'none';
199		}
200		// add management button to update the decision
201		document.getElementById('cookiesck_options').onclick = function(){
202			document.getElementById('cookiesck_interface').style.display = 'block';
203			document.getElementById('cookiesck_overlay').style.display = 'block';
204		}
205	}
206
207	function initIframes() {
208		let iframes = document.querySelectorAll('.cookiesck-iframe-wrap');
209		debug('iframes  : ');
210		debug(iframes);
211		iframes.forEach(function(iframe) {
212			iframe.onclick = function() {
213				if (! confirm(COOKIESCK.TEXT.CONFIRM_IFRAMES)) return; 
214				this.outerHTML = this.outerHTML.replace('data-cookiesck-src', 'src');
215				loadIframes();
216				setCookie('cookiesckiframes', '1', COOKIESCK.LIFETIME);
217			}
218		});
219	}
220
221	function setCookie(c_name,value,exdays) {
222		debug('setCookie  : {name : ' + c_name + ', value : ' + value + ', exdays : ' + exdays);
223		var exdate=new Date(Date.now());
224		exdate.setDate(exdate.getDate() + parseInt(exdays));
225		var c_value=escape(value) + ((exdays===null) ? "" : "; expires="+exdate.toUTCString()) + "; path=/";
226		document.cookie=c_name + "=" + c_value;
227	}
228
229	function readCookie(name) {
230		debug('readCookie  : ' + name);
231		var nameEQ = name + "=";
232		var cooks = document.cookie.split(';');
233		for(var i=0;i < cooks.length;i++) {
234			var c = cooks[i];
235			while (c.charAt(0)==' ') c = c.substring(1,c.length);
236				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
237			}
238		return null;
239	}
240
241	function removeCookie(platformName) {
242		debug('removeCookie  : ' + platformName);
243
244		var keys = getKeyFromPlatform(platformName);
245		var domain = location.hostname.split('.').reverse();
246		if (domain.length == 1) {
247			domain = '.' + domain[0];
248		} else {
249			domain = '.' + domain[1] + '.' + domain[0];
250		}
251
252		for (var i=0; i < keys.length; i++) {
253			debug('Platform Key to remove  : ' + keys[i]);
254			let cookie = keys[i] + "=; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";
255			document.cookie = cookie;
256			document.cookie = cookie + '; domain=' + domain;
257		}
258	}
259
260	function getKeyFromPlatform(platformName) {
261		var list = JSON.parse(COOKIESCK.LIST.replace(/\|QQ\|/g, '"'));
262		var keys = new Array();
263		for (const category in list) {
264			for (const platform in list[category]['platforms']) {
265				if (platform === platformName) {
266					for (var cookie in list[category]['platforms'][platform]['cookies']) {
267						keys.push(list[category]['platforms'][platform]['cookies'][c
267ookie]['key']);
268					}
269				}
270			}
271		}
272
273		return keys;
274	}
275
276	function toObject() {
277		let list = new Object();
278		let rows = COOKIESCK.VALUE.split('|ck|');
279		for (var i=0; i < rows.length; i++) {
280			let cols = rows[i].split('|val|');
281			list[cols[0]] = cols[1];
282		}
283		return list;
284	}
285
286	function doAction(btn, action) {
287		btn.parentNode.querySelectorAll('.cookiesck_button').forEach(function(button) {
288			button.classList.remove('cookiesck-active');
289		});
290		btn.classList.add('cookiesck-active');
291		updateCookieValue();
292		// if (opts.reload === '1') location.reload();
293	}
294
295	function updateCookieValue() {
296		debug('updateCookieValue');
297		let interfac = document.getElementById('cookiesck_interface');
298		let list = new Array();
299		let platforms = interfac.querySelectorAll('.cookiesck-platform');
300		platforms.forEach(function(platform) {
301			let selection = platform.querySelector('.cookiesck_button.cookiesck-active');
302			let name = platform.getAttribute('data-platform');
303			if (selection && selection.classList.contains('cookiesck-accept')) {
304				list.push(name + '|val|1');
305				// trigger event
306				let event = new CustomEvent('cookieckstate', { "detail": {"name": name, "state": "1"} });
307				document.dispatchEvent(event);
308				debug('cookieckstate  : {name : ' + name + ', state : 1');
309			} else {
310				list.push(name + '|val|0');
311				removeCookie(name);
312				// trigger event
313				let event = new CustomEvent('cookieckstate', { "detail": {"name": name, "state": "0"} });
314				document.dispatchEvent(event);
315				debug('cookieckstate  : {name : ' + name + ', state : 0');
316			}
317		});
318		COOKIESCK.VALUE = list.join('|ck|');
319		setCookie('cookiesck', encodeURIComponent(COOKIESCK.VALUE), opts.lifetime);
320		if (COOKIESCK.LOG === '1') {
321			// if not unique key has been set, set it now with the session ID
322			if (! readCookie('cookiesckuniquekey')) {
323				setCookie('cookiesckuniquekey', COOKIESCK.UNIQUE_KEY, opts.lifetime);
324			}
325		}
326		doAjax(location.href, 'set_cookieck=update&cookiesck_vars=' + encodeURIComponent(COOKIESCK.VALUE));
327	}
328
329	function acceptAll() {
330		let interfac = document.getElementById('cookiesck_interface');
331		interfac.querySelectorAll('.cookiesck-active').forEach(function(btn) { btn.classList.remove('cookiesck-active'); });
332		interfac.querySelectorAll('.cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
333		loadIframes();
334		// trigger event
335		let event = new CustomEvent('cookieckstate', { "detail": {"name": "all", "state": "1"} });
336		document.dispatchEvent(event);
337	}
338
339	function declineAll() {
340		let interfac = document.getElementById('cookiesck_interface');
341		interfac.querySelectorAll('.cookiesck-active').forEach(function(btn) { btn.classList.remove('cookiesck-active'); });
342		interfac.querySelectorAll('.cookiesck-decline').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
343		// force essential to be active
344		if (interfac.querySelector('[data-category="essential"]')) {
345			interfac.querySelectorAll('[data-category="essential"] .cookiesck-accept').forEach(function(btn) { btn.classList.add('cookiesck-active'); });
346		}
347		// trigger event
348		let event = new CustomEvent('cookieckstate', { "detail": {"name": "all", "state": "0"} });
349		document.dispatchEvent(event);
350	}
351
352	function loadIframes() {
353		let iframes = document.querySelectorAll('.cookiesck-iframe-wrap');
354		iframes.forEach(function(iframetoenable) {
355			iframetoenable.closest('.cookiesck-iframe-wrap').className = 'cookiesck-iframe-wrap-allowed';
356			iframetoenable.outerHTML = iframetoenable.outerHTML.replace('data-cookiesck-src', 'src');
357		});
358	}
359
360	function doAjax(url, vars) {
361		// ancien code de compatibilité, aujourd’hui inutile
362		if (window.XMLHttpRequest) { // Mozilla, Safari, IE7+...
363			var httpRequest = new XMLHttpRequest();
364		}
365		else if (window.ActiveXObject) { // IE 6 et antérieurs
366			var httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
367		}
368		httpRequest.onreadystatechange = function() {
369			// instructions de traitement de la réponse
370		};
371		httpRequest.open('POST', url, true);
372		httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
373		httpRequest.send(vars);
374	}
375
376	function debug(str) {
377		if (COOKIESCK.DEBUG === '1') {
378			console.log(str);
379		}
380	}
381
382	window.Cookiesck = Cookiesck;
383	window.ckInitCookiesckIframes = initIframes;
384})();
385
386// initialize the setter and getter for the cookies
387if (! document.__defineGetter__) {
388	Object.defineProperty(document, 'cookie',{
389		get: function g(){ return ''; },
390		set: function h(){ return true;}
391	});
392} else {
393	var oldSetter = document.__lookupSetter__('cookie');
394	var oldGetter = document.__lookupGetter__('cookie');
395	if (oldSetter) {
396		Object.defineProperty(document, 'cookie', {
397			get: function g(){ return oldGetter.call(document); },
398			set: function h(v){
399				let name = v.split('=')[0];
400
401				if (COOKIESCK.DEBUG === '1') {
402					console.log('v.match(/cookiesck\=/)');
403					console.log(v.match(/cookiesck\=/));
404					console.log('COOKIESCK.VALUE');
405					console.log(COOKIESCK.VALUE);
406					console.log('COOKIESCK.ALLOWED');
407					console.log(COOKIESCK.ALLOWED);
408					console.log('COOKIESCK.ALLOWED.indexOf(name)');
409					console.log(COOKIESCK.ALLOWED.indexOf(name));
410					console.log('ckCookiesSearchNameIn(name, COOKIESCK.ALLOWED)');
411					console.log(ckCookiesSearchNameIn(name, COOKIESCK.ALLOWED));
412				}
413
414				if(v.match(/cookiesck\=/) || COOKIESCK.VALUE === 'yes' || COOKIESCK.ALLOWED.indexOf(name) != -1 || ckCookiesSearchNameIn(name, COOKIESCK.ALLOWED)) {
415					oldSetter.call(document, v);
416					if (COOKIESCK.DEBUG === '1') {
417						console.log('>> set cookie allowed :');
418						console.log(name);
419					}
420				} else {
421					let cookie = name + "=; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/;";
422					oldSetter.call(document, cookie);
423					oldSetter.call(document, 'crisp-client%2Fsession%2Ffa03b9fb-a103-4601-adb5-5922261174d4=; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/;');
424					if (COOKIESCK.DEBUG === '1') {
425						console.log('>> set cookie blocked for :');
426						console.log(name);
427					}
428				}
429				return true;
430			}
431		});
432	}
433}
434
435function ckCookiesSearchNameIn(name, list) {
436	for (var i=0; i<list.length; i++) {
437		if (name.substr(0, list[i].length) == list[i]) return true;
438	}
439	return false;
440}
441
442// example of how to get the event
443//document.addEventListener("cookieckstate", function(e) {
444//	console.log(e.detail)
445//	console.log(e.detail.name);
446//	console.log(e.detail.state);
447//});
448

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.