1var EuroClixGoogleLogin = (function() { 2 var client; 3 var access_token; 4 var googlelogin; 5 var tokenloginlongtail; 6 var tokenlongtail; 7 var gsiReadyCallbacks = []; 8 var gsiScriptRequested = false; 9 var gsiCheckTimer = null; 10 11 function oauth2Field(id) { 12 return document.getElementById(id); 13 } 14 15 function setFieldValue(id, value) { 16 var field = oauth2Field(id); 17 if (field) { 18 field.value = value; 19 } 20 } 21 22 function submitForm(id) { 23 var form = oauth2Field(id); 24 if (form) { 25 form.submit(); 26 } 27 } 28 29 function isGsiAvailable() { 30 return typeof google !== 'undefined' 31 && google.accounts 32 && google.accounts.oauth2; 33 } 34 35 function flushGsiReadyCallbacks() { 36 if (!isGsiAvailable()) { 37 return; 38 } 39 var callbacks = gsiReadyCallbacks.slice(); 40 gsiReadyCallbacks = []; 41 for (var i = 0; i < callbacks.length; i++) { 42 callbacks[i](); 43 } 44 } 45 46 function scheduleGsiReadyCheck() { 47 if (gsiCheckTimer) { 48 return; 49 } 50 var attempts = 0; 51 gsiCheckTimer = setInterval(function() { 52 attempts++; 53 if (isGsiAvailable() || attempts >= 100) { 54 clearInterval(gsiCheckTimer); 55 gsiCheckTimer = null; 56 flushGsiReadyCallbacks(); 57 } 58 }, 100); 59 } 60 61 function ensureGsiScript() { 62 if (gsiScriptRequested) { 63 return; 64 } 65 gsiScriptRequested = true; 66 67 var existing = document.querySelector('script[src*="accounts.google.com/gsi/client"]'); 68 if (existing) { 69 existing.addEventListener('load', flushGsiReadyCallbacks); 70 existing.addEventListener('error', flushGsiReadyCallbacks); 71 return; 72 } 73 74 var script = document.createElement('script'); 75 script.src = 'https://accounts.google.com/gsi/client'; 76 script.async = true; 77 script.defer = true; 78 script.onload = flushGsiReadyCallbacks; 79 script.onerror = flushGsiReadyCallbacks; 80 document.head.appendChild(script); 81 } 82 83 function runWhenGsiReady(callback) { 84 if (isGsiAvailable()) { 85 callback(); 86 return; 87 } 88 gsiReadyCallbacks.push(callback); 89 ensureGsiScript(); 90 scheduleGsiReadyCheck(); 91 } 92 93 function initClient() { 94 var clientIdElement = oauth2Field('ggclid-login') || oauth2Field('ggclid'); 95 if (!clientIdElement || !clientIdElement.value) { 96 return false; 97 } 98 if (!isGsiAvailable()) { 99 return false; 100 } 101 if (client) { 102 return true; 103 } 104 105 client = google.accounts.oauth2.initTokenClient({ 106 client_id: clientIdElement.value, 107 scope: 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email', 108 callback: function(tokenResponse) { 109 if (!tokenResponse || tokenResponse.error) { 110 return; 111 } 112 access_token = tokenResponse.access_token; 113 if (googlelogin) { 114 setFieldValue('tokenGl', access_token); 115 submitForm('googlelogin'); 116 } 117 if (tokenloginlongtail) { 118 setFieldValue('gllongtailtoken', access_token); 119 submitForm('googlelongtail'); 120 } 121 if (tokenlongtail) { 122 setFieldValue('registailgoogletoken', access_token); 123 submitForm('googletailregistrate'); 124 } 125 }, 126 }); 127 return true; 128 } 129 130 function requestGoogleToken(setFlag) { 131 runWhenGsiReady(function() { 132 setFlag(); 133 if (!client && !initClient()) { 134 return; 135 } 136 if (client) { 137 client.requestAccessToken({ prompt: 'select_account' }); 138 } 139 }); 140 } 141 142 function getTokenLogin() { 143 requestGoogleToken(function() { 144 googlelogin = true; 145 }); 146 } 147 148 function getTokenLoginLongtail() { 149 requestGoogleToken(function() { 150 tokenloginlongtail = true; 151 }); 152 } 153 154 function getTokenLongtail() { 155 requestGoogleToken(function() { 156 tokenlongtail = true; 157 }); 158 } 159 160 function revokeToken() { 161 if (access_token && isGsiAvailable()) { 162 google.accounts.oauth2.revoke(access_token, function() { 163 console.log('access token revoked'); 164 }); 165 } 166 } 167 168 return { 169 initClient: initClient, 170 getTokenLogin: getTokenLogin, 171 getTokenLoginLongtail: getTokenLoginLongtail, 172 getTokenLongtail: getTokenLongtail, 173 revokeToken: revokeToken 174 }; 175})(); 176 177window.getTokenLogin = EuroClixGoogleLogin.getTokenLogin; 178window.getTokenLoginLongtail = EuroClixGoogleLogin.getTokenLoginLongtail; 179window.getTokenLongtail = EuroClixGoogleLogin.getTokenLongtail; 180window.initGoogleLoginClient = EuroClixGoogleLogin.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.