PageSourceSearch

https://www.euroclix.nl/assets/f93cbd4b2ba5510d/ctx/resources/js/gooauth2_reg.js

js euroclix.nl collected 2026-10-01 10:33:18 UTC 3,440 bytes, 147 lines download raw bytes

1var EuroClixGoogleReg = (function() {
2	var client;
3	var access_token;
4	var gsiReadyCallbacks = [];
5	var gsiScriptRequested = false;
6	var gsiCheckTimer = null;
7
8	function oauth2RegField(id) {
9		return document.getElementById(id);
10	}
11
12	function findGoogleTokenField() {
13		var form = oauth2RegField('googleregistrate');
14		if (form) {
15			var field = form.querySelector('#regisgoogletoken, [name="regisgoogletoken"]');
16			if (field) {
17				return field;
18			}
19		}
20		return oauth2RegField('regisgoogletoken');
21	}
22
23	function isGsiAvailable() {
24		return typeof google !== 'undefined'
25			&& google.accounts
26			&& google.accounts.oauth2;
27	}
28
29	function flushGsiReadyCallbacks() {
30		if (!isGsiAvailable()) {
31			return;
32		}
33		var callbacks = gsiReadyCallbacks.slice();
34		gsiReadyCallbacks = [];
35		for (var i = 0; i < callbacks.length; i++) {
36			callbacks[i]();
37		}
38	}
39
40	function scheduleGsiReadyCheck() {
41		if (gsiCheckTimer) {
42			return;
43		}
44		var attempts = 0;
45		gsiCheckTimer = setInterval(function() {
46			attempts++;
47			if (isGsiAvailable() || attempts >= 100) {
48				clearInterval(gsiCheckTimer);
49				gsiCheckTimer = null;
50				flushGsiReadyCallbacks();
51			}
52		}, 100);
53	}
54
55	function ensureGsiScript() {
56		if (gsiScriptRequested) {
57			return;
58		}
59		gsiScriptRequested = true;
60
61		var existing = document.querySelector('script[src*="accounts.google.com/gsi/client"]');
62		if (existing) {
63			existing.addEventListener('load', flushGsiReadyCallbacks);
64			existing.addEventListener('error', flushGsiReadyCallbacks);
65			return;
66		}
67
68		var script = document.createElement('script');
69		script.src = 'https://accounts.google.com/gsi/client';
70		script.async = true;
71		script.defer = true;
72		script.onload = flushGsiReadyCallbacks;
73		script.onerror = flushGsiReadyCallbacks;
74		document.head.appendChild(script);
75	}
76
77	function runWhenGsiReady(callback) {
78		if (isGsiAvailable()) {
79			callback();
80			return;
81		}
82		gsiReadyCallbacks.push(callback);
83		ensureGsiScript();
84		scheduleGsiReadyCheck();
85	}
86
87	function initClient() {
88		var clientIdElement = oauth2RegField('ggclid-reg') || oauth2RegField('ggclid');
89		if (!clientIdElement || !clientIdElement.value) {
90			return false;
91		}
92		if (!isGsiAvailable()) {
93			return false;
94		}
95		if (client) {
96			return true;
97		}
98
99		client = google.accounts.oauth2.initTokenClient({
100			client_id: clientIdElement.value,
101			scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email',
102			callback: function(tokenResponse) {
103				if (!tokenResponse || tokenResponse.error) {
104					return;
105				}
106				access_token = tokenResponse.access_token;
107				var tokenField = findGoogleTokenField();
108				var form = oauth2RegField('googleregistrate');
109				if (tokenField) {
110					tokenField.value = access_token;
111				}
112				if (form) {
113					form.submit();
114				}
115			},
116		});
117		return true;
118	}
119
120	function getTokenRegist() {
121		runWhenGsiReady(function() {
122			if (!client && !initClient()) {
123				return;
124			}
125			if (client) {
126				client.requestAccessToken({ prompt: 'select_account' });
127			}
128		});
129	}
130
131	function revokeToken() {
132		if (access_token && isGsiAvailable()) {
133			google.accounts.oauth2.revoke(access_token, function() {
134				console.log('access token revoked');
135			});
136		}
137	}
138
139	return {
140		initClient: initClient,
141		getTokenRegist: getTokenRegist,
142		revokeToken: revokeToken
143	};
144})();
145
146window.getTokenRegist = EuroClixGoogleReg.getTokenRegist;
147window.initGoogleRegClient = EuroClixGoogleReg.initClient;

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.