1/* global UserStatusIs */ 2 3window.vfQ = window.vfQ || []; 4 5const updateBCProfile = (profileKey, status) => { 6 let updateUserProfile = function () { 7 const profile = blueConicClient.profile.getProfile(); 8 profile.setValue(profileKey, status); 9 blueConicClient.profile.updateProfile(); 10 }; 11 12 if ( 13 typeof window.blueConicClient !== "undefined" && 14 typeof window.blueConicClient.event !== "undefined" && 15 typeof window.blueConicClient.event.subscribe !== "undefined" 16 ) { 17 updateUserProfile(); 18 } else { 19 window.addEventListener( 20 "onBlueConicLoaded", 21 updateUserProfile, 22 false 23 ); 24 } 25}; 26 27const MTM_ViaFoura = { 28 hasInit: false, 29 30 async init() { 31 32 if(MTM_ViaFoura.hasInit){ 33 return; 34 } 35 36 MTM_ViaFoura.hasInit = true; 37 38 MTM_ViaFoura.user = {}; 39 40 vfQ.push(MTM_ViaFoura.overrideViaFouraLoginToAuth0); 41 vfQ.push(MTM_ViaFoura.forceAuth0LogoutWithViaFoura); 42 vfQ.push(MTM_ViaFoura.logUserIn); 43 vfQ.push(MTM_ViaFoura.listenForLoginFailure); 44 vfQ.push(MTM_ViaFoura.generateCommentAd); 45 46 MTM_ViaFoura.handleCommentsCountClick(); 47 48 if ( 'undefined' !== typeof UserStatusIs && 'function' === typeof UserStatusIs.any ) { 49 50 UserStatusIs.any(function(){ 51 52 if ( user_state === 'loggedout' ) { 53 console.log("============================"); 54 console.log("=== Should log user out ==="); 55 console.log("============================"); 56 57 vfQ.push(MTM_ViaFoura.logUserOut); 58 } 59 60 }); 61 } else { 62 console.error('UserStatusIs is not up to date'); 63 } 64 }, 65 66 async logUserOut() { 67 console.log('Logging user out of VF due to no active Auth0 session.'); 68 await window.vf.session.logout(); 69 }, 70 71 listenForLoginFailure() { 72 // https://documentation.viafoura.com/docs/viafoura-events#login 73 window.vf.$subscribe( 74 "login", 75 "failure", 76 function (errorContext, loginContext) { 77 78 updateBCProfile("viafoura_fail", errorContext.reason); 79 80 if (errorContext.error_key == 'login_banned' && errorContext.isPermanent == '1') { 81 document.getElementById("banreason").innerText = 'Permanent ban: ' + errorContext.reason; 82 document.getElementById("banreason").classList.add('showing'); 83 return; 84 } else if (errorContext.error_key == 'login_banned' && errorContext.isPermanent == '0') { 85 var expire = new Date(errorContext.endDate); 86 var expire_string = expire.getFullYear() + '/' + (expire.getMonth() + 1) + '/' + expire.getDate() 87 document.getElementById("banreason").innerText = 'Banned until: ' + expire_string + '. Reason: ' + errorContext.reason; 88 document.getElementById("banreason").classList.add('showing'); 89 return; 90 } else { 91 console.log(errorContext.reason); 92 } 93 } 94 ); 95 }, 96 97 generateCommentAd() { 98 window.vf.$subscribe("vf-ads", "requestCommentAd", ( slotName ) => { 99 100 var e = document.getElementById( slotName ); 101 var d = document.createElement('div'); 102 103 d.classList.add( 'opscoad-vf-promo-comments-1' ); 104 d.setAttribute('data-unit', adUnit ); 105 106 e.appendChild( d ); 107 108 }); 109 }, 110 111 overrideViaFouraLoginToAuth0() { 112 let doSignIn = () => { 113 window.vf.$publish("tray", "close"); 114 flipPay.signIn(); 115 return false; 116 }; 117 window.vf.$prepublish((channel, event, ...args) => { 118 if (channel === "authentication" && (event === "required" || event === 'needed')) { 119 return doSignIn(); 120 } else { 121 return { channel, event, args }; 122 } 123 }); 124 125 window.vf.$subscribe('tray', 'open', () => { 126 if(! MTM_ViaFoura.user){ 127 return doSignIn(); 128 } 129 }); 130 }, 131 132 forceAuth0LogoutWithViaFoura() { 133 window.vf.$subscribe("authentication", "logout", () => { 134 // Add here the handler to trigger your authentication logout flow. 135 if ( 'undefined' !== typeof flipPay ) { 136 console.log( 'forceAuth0LogoutWithViaFoura' ); 137 flipPay.signOut(); 138 } 139 }); 140 }, 141 142 parseJwt(token) { 143 var base64Url = token.split('.')[1]; 144 var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); 145 var jsonPayload = decodeURIComponent(window.atob(base64).split('').map(function (c) { 146 return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); 147 }).join('')); 148 149 return JSON.parse(jsonPayload); 150 }, 151 152 async logUserIn() { 153 if ( MTMFlipPay.hasCookie() ) { 154 let user = await vf.context.get('user'); 155 let hasUpdatedName = false;
156 let jwt = MTM_ViaFoura.parseJwt(fpUserResponse.id_token); 157 158 if(jwt.alias !== user.name){ 159 hasUpdatedName = true; 160 } 161 162 if (user.user_privilege == "guest" || hasUpdatedName) { 163 if (fpUserResponse && fpUserResponse.id_token) { 164 window.vf.session.login.openIdConnect(fpUserResponse.id_token).catch(e => { 165 // error logging user in. Think about maybe logging the user out when this happens 166 // this could be an expires token maybe? 167 }).then(res => { 168 MTM_ViaFoura.user = user; 169 }); 170 } 171 }else{ 172 MTM_ViaFoura.user = user; 173 } 174 } 175 }, 176 177 /** 178 * Add a click event to the comments count item in the article header. 179 * 180 * @returns {void} 181 */ 182 handleCommentsCountClick() { 183 184 const commentsEl = document.getElementById('viafoura-comments'); 185 186 if ( commentsEl ) { 187 document.addEventListener('click', function(event) { 188 if (event.target.classList.contains('vf-comments-count')) { 189 commentsEl.scrollIntoView(); 190 } 191 }); 192 } 193 } 194}; 195 196document.addEventListener( 'DOMContentLoaded', function() { 197 UserStatusIs.any(() => { 198 MTM_ViaFoura.init(); 199 }); 200}); 201 202 203 204function showCommentsDisabledExplanation() { 205 const init = () => { 206 const moreText = document.querySelector('.comments-disabled .text-panel-expanded'); 207 const initialText = document.querySelector('.no-comments'); 208 209 if (! moreText || ! initialText){ 210 return; 211 } 212 213 moreText.querySelector('span').addEventListener('click', toggleHide); 214 initialText.querySelector('span').addEventListener('click', toggleHide); 215 216 function toggleHide() { 217 moreText.classList.toggle('hidden'); 218 // initialText.classList.toggle('hidden'); 219 } 220 }; 221 222 document.addEventListener('DOMContentLoaded', init); 223} 224 225showCommentsDisabledExplanation();; 226/* global Connext */ 227 228/** 229 * This while script can be replaced with some simple css that change the display on commenting-profile-information and commenting-profile-no-user based on body.user-known 230 */ 231const MTM_Viafoura_Username = (function (undefined) { 232 "use strict"; 233 234 window.addEventListener("DOMContentLoaded", function () { 235 UserStatusIs.any(function(){ 236 if (document.body.classList.contains("user-known")) { 237 init(); 238 } 239 }); 240 }); 241 242 function setFieldValues(args){ 243 for (let i = 0; i < args.length; i++ ) { 244 args[i].node.value = args[i].val; 245 } 246 } 247 248 async function init() { 249 let information_container = document.querySelector(".commenting-profile-information"); 250 251 let usernameContainer = document.querySelector(".commenting-profile-no-user"); 252 253 if( usernameContainer){ 254 usernameContainer.classList.add("hidden"); 255 } 256 257 if( information_container ){ 258 information_container.classList.remove('hidden'); 259 }else{ 260 return; 261 } 262 } 263 264 return { 265 setFieldValues, 266 }; 267})(); 268;
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.