summaryrefslogtreecommitdiff
path: root/backend/instance/nocookies/data/js/common8.js
blob: 5884bd33f1bfdec3c63ed77e28450692ec9d89a4 (plain)
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
function _sl(selector, container) {
	return (container || document).querySelector(selector);
}

function _id(id) {
	return document.getElementById(id);
}


var main_interval = setInterval(function() {
	var html = _sl('html');
	
	if (!html || /idc8_350/.test(html.className))
		return;
	
	clearInterval(main_interval);
	
	html.className += ' idc8_350';
	
	var counter = 0, host_parts = document.location.hostname.split('.'), interval = setInterval(function() {
		
		var element;
		
		if (host_parts[0] == 'consent') {
			if (document.location.pathname == '/m') {
				
				if (host_parts[1] == 'youtube')
					element = _sl('div + form[action*="//consent."][action$="/save"] button, .basebutton + form[action*="//consent."][action*="/save"] .button');
				else
					element = _sl('form[action*="//consent."][action$="/save"]:first-of-type:not(:only-of-type) button');
				
				if (element) {
					element.click();
					counter = 299;
				}
			}
			
			
			// Mobile only: 1. google.co.uk (or in FF Nightly, on google.com search results) 2. YT only, a copy or the desktop selector
			
			else if (document.location.pathname == '/ml') {
				element = _sl('.saveButtonContainerNarrowScreen > form:last-child .button, .basebutton + form[action*="//consent."][action*="/save"] .button');
				
				if (element) {
					element.click();
					counter = 299;
				}
			}
		}
		
		
		// https://www.google.com/finance/
		
		else if (document.location.hostname == 'ogs.google.com' && document.location.pathname == '/widget/callout') {
			if (document.evaluate('//span[contains(text(), "This site uses cookies")]', document, null, XPathResult.ANY_TYPE, null).iterateNext()) {
				_sl('button').click();
				counter = 299;
			}
		}
		
		else {
			// The latest cookie popup, desktop and mobile
			
			var container = _sl('div[aria-modal="true"][style*="block"]');
			
			if (container && _sl('a[href*="policies.google.com/technologies/cookies"]', container)) {
				_sl('button + button', container).click();
				
				// Autofocus on the search field
				element = _sl('form[role="search"][action="/search"]:not([id]) input[aria-autocomplete="both"]');
				if (element) element.focus();
				
				counter = 299;
			}
			
			// General privacy reminder
			element = _sl('form[action^="/signin/privacyreminder"] > div > span > div:not([role]) > div:not([tabindex]) span + div');
			if (element) element.click();
			
			// #cns=1
			if (document.location.hash == '#cns=1')
				document.location.hash = '#cns=0';
		}
		
		counter++;
		
		if (counter == 300)
			clearInterval(interval);
	
	}, 250 + counter*10);
}, 250);