1(function (Waterdeep, undefined) { 2 "use strict"; 3 4 5 Waterdeep.Authentication = { 6 SidebarVideoChoiceCookieName: "DDBLoginSidebarVideoChoice", 7 VideoSources: [ 8 { 9 id: 0, 10 url: "https://www.dndbeyond.com/login-sidebar-video/sidebar_video_1.webm", 11 averageColor: "#2e3949" 12 }, 13 { 14 id: 1, 15 url: "https://www.dndbeyond.com/login-sidebar-video/sidebar_video_2.webm", 16 averageColor: "#5c473f", 17 offset: { 18 left: "-75px" 19 } 20 } 21 ], 22 handleAuthResponse: function handleAuthResponse(authResponse, errorsElement, subtextElement, titleElement) { 23 if (authResponse.success) { 24 Waterdeep.Authentication.redirectFromAuthResponse(authResponse); 25 } else { 26 var _errorsElement = errorsElement || document.querySelector('.ddb-login-container__header__errors'); 27 var _subtextElement = subtextElement || document.querySelector('.ddb-login-container__header__errors--subtext'); 28 var _titleElement = titleElement || document.querySelector('.ddb-login-container__header__title'); 29 30 if (_errorsElement) { 31 Waterdeep.Authentication.writeMessageToElement(authResponse.message, _errorsElement); 32 } 33 34 if (_subtextElement) { 35 Waterdeep.Authentication.writeMessageToElement('You can link additional accounts to your D&D Beyond account after signing in.', _subtextElement); 36 } 37 38 if (_titleElement) { 39 Waterdeep.Authentication.writeMessageToElement('That Didn\'t Work', _titleElement); 40 } 41 } 42 }, 43 redirectFromAuthResponse: function redirectFromAuthResponse(authResponse) { 44 var redirectUrl = ""; 45 var idCode = "code=" + authResponse.code; 46 var returnUrl = "returnUrl=" + authResponse.returnUrl; 47 48 if (authResponse.nextStepUrl) { 49 redirectUrl = authResponse.nextStepUrl; 50 redirectUrl += "?" + idCode; 51 redirectUrl += "&" + returnUrl; 52 53 window.location.replace(redirectUrl); 54 return; 55 } 56 57 window.location.replace(authResponse.returnUrl); 58 return; 59 }, 60 writeMessageToElement: function writeMessageToElement(message, element) { 61 element.innerHTML = message; 62 }, 63 getReturnUrlFromUrl: function getReturnUrlFromUrl() { 64 return getQueryStringValue('returnUrl'); 65 }, 66 initializeTwitchAuthButtonHandler: function initializeTwitchAuthButtonHandler(loginUrl) { 67 var loginWithTwitchButton = document.querySelector('#signin-with-twitch'); 68 69 if (loginWithTwitchButton) { 70 loginWithTwitchButton.addEventListener('click', function (event) { 71 event.preventDefault(); 72 73 window.location.replace(loginUrl); 74 }); 75 } 76 }, 77 initializeGoogleAuthButtonHandler: function initializeGoogleAuthButtonHandler(googleAuthClientId, googleCallbackUrl, googleApi, errorsElement, subtextElement, titleElement) { 78 var loginWithGoogleButton = document.querySelector('#signin-with-google'); 79 var _returnUrl = Waterdeep.Authentication.getReturnUrlFromUrl(); 80 81 if (loginWithGoogleButton) { 82 loginWithGoogleButton.addEventListener('click', function (event) { 83 event.preventDefault(); 84 85 googleApi.auth2.authorize({ 86 client_id: googleAuthClientId, 87 scope: 'email profile openid', 88 prompt: 'select_account', 89 response_type: 'code id_token', 90 }, function (response) { 91 var xhr = new XMLHttpRequest(); 92 xhr.open("POST", googleCallbackUrl, true); 93 xhr.setRequestHeader("Content-Type", "application/json"); 94 xhr.onreadystatechange = function () { 95 if (xhr.readyState === 4 && xhr.status === 200) { 96 var response = JSON.parse(xhr.response); 97 Waterdeep.Authentication.handleAuthResponse(response, errorsElement, subtextElement, titleElement); 98 } 99 }; 100 101 if (response.error) { 102 switch (response.error) { 103 case "idpiframe_initialization_failed": { 104 var errorMessage = ""; 105 if (response.details.indexOf("origin") > -1) { 106 errorMessage = 'Oh no - requests may only come from www.dndbeyond.com'; 107 } else { 108 errorMessage = 'Oh no - we couldn\'t link your Google account because you have third-party cookies blocked in this browser. Please enable third-party cookies, refresh, and try again. <br><a target="_blank" href="https://www.enable-javascript.com/">Learn More</a>'; 109 } 110 Waterdeep.Authentication.addGoogleErrorToGoogleErrorElement(errorMessage); 111 return; 112 } 113 case "popup_closed_by_user": { 114 return; 115 } 116 case "popup_blocked_by_browser": { 117 Waterdeep.Authentication.addGoogleErrorToGoogleErrorElement('Oh no - your browser is blocking pop-ups!'); 118 return; 119 }
120 case "access_denied": { 121 return; 122 } 123 default: { 124 if (response.details != null && response.details.length > 0) { 125 Waterdeep.Authentication.addGoogleErrorToGoogleErrorElement(response.details); 126 } 127 return; 128 } 129 } 130 } 131 132 if (response.id_token) { 133 xhr.send(JSON.stringify({ 134 code: response.id_token, 135 returnUrl: _returnUrl 136 })); 137 } else { 138 Waterdeep.Authentication.addGoogleErrorToGoogleErrorElement("Something went wrong! We've logged the error, but please refresh and try again."); 139 } 140 }); 141 }); 142 } 143 }, 144 addGoogleErrorToGoogleErrorElement: function addGoogleErrorToGoogleErrorElement(errorMessage) { 145 var errorEl = document.querySelector('.ddb-login-container__header__errors--google') || document.querySelector('.ddb-login-container__header__errors'); 146 Waterdeep.Authentication.writeMessageToElement(errorMessage, errorEl); 147 try { 148 handleErrorForAnalytics('google', errorMessage); 149 } catch (e) { 150 console.log(e.message); 151 } 152 }, 153 sidebarVideoChooser: function sidebarVideoChooser(sidebarElement) { 154 var sidebarVideoElement = sidebarElement.querySelector('video'); 155 156 // select a video source 157 var source = getSourceFromCookieOrRandom(document.cookie, Waterdeep.Authentication.VideoSources); 158 159 // style 160 if (source.averageColor) { 161 sidebarElement.style.backgroundColor = source.averageColor; 162 } 163 if (source.offset) { 164 if (source.offset.left) { 165 sidebarVideoElement.style.left = source.offset.left; 166 } 167 } 168 169 // set video src to source video url 170 sidebarVideoElement.src = source.url; 171 172 // save source to 5 minute cookie 173 setVideoChoiceCookie({ value: source.id }, Waterdeep.Authentication.VideoSources); 174 }, 175 setMarketOptInCookie: function setMarketOptInCookie(isMarketOptInChecked) { 176 var expirationTimeInMinutes = 60; 177 var cookie = { 178 name: "marketing_opt_in", 179 value: isMarketOptInChecked, 180 expireDate: new Date(new Date().getTime() + (expirationTimeInMinutes * 60000)).toUTCString() 181 }; 182 document.cookie = cookie.name + "=" + cookie.value + ";expires=" + cookie.expireDate + ";path=/"; 183 } 184 }; 185 186 var getQueryStringValue = function getQueryStringValue(field) { 187 var href = window.location.href; 188 var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i'); 189 var string = reg.exec(href); 190 return string ? string[1] : null; 191 }; 192 193 var setVideoChoiceCookie = function setVideoChoiceCookie(cookie, sources) { 194 if (cookie.name == null) { 195 cookie.name = Waterdeep.Authentication.SidebarVideoChoiceCookieName; 196 } 197 if (cookie.value == null) { 198 cookie.value = getRandomIndexFromArray(sources) 199 } 200 if (cookie.expireDate == null) { 201 var minutesAsMilliseconds = function (minutes) { return minutes * 60000 }; 202 cookie.expireDate = new Date(new Date().getTime() + minutesAsMilliseconds(5)).toUTCString(); 203 } 204 if (cookie.path == null) { 205 cookie.path = "/" 206 } 207 208 document.cookie = cookie.name + "=" + cookie.value + ";expires=" + cookie.expireDate + ";path=" + cookie.path; 209 }; 210 211 var getCookie = function getCookie(cookies, name) { 212 cookies = cookies.split(';'); 213 for (var i = 0; i < cookies.length; i++) { 214 var cookie = cookies[i]; 215 while (cookie.charAt(0) === ' ') { 216 cookie = cookie.substring(1); 217 } 218 if (cookie.indexOf(name) === 0) { 219 return cookie.substring(name.length + 1, cookie.length); 220 } 221 } 222 223 return null; 224 }; 225 226 var getRandomIndexFromArray = function getRandomFromArray(arr) { 227 return Math.floor(Math.random() * arr.length); 228 }; 229 230 var getSourceFromCookieOrRandom = function (cookies, videoSources) { 231 var cookieCachedSourceIndex = getCookie(cookies, Waterdeep.Authentication.SidebarVideoChoiceCookieName); 232 if (cookieCachedSourceIndex) { 233 return videoSources[cookieCachedSourceIndex]; 234 } else { 235 return videoSources[getRandomIndexFromArray(videoSources)]; 236 } 237 } 238 239})(Waterdeep = window.Waterdeep || {});
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.