1(() => { 2 const CLASS = '--logged-in'; 3 const MOUNT_SELECTOR = '[id^="vue-customer-app-"]'; 4 5 const getMount = () => document.querySelector(MOUNT_SELECTOR); 6 7 const getHost = () => { 8 const mount = getMount(); 9 10 // If nothing mounted yet, fallback to the first customer-area section if present 11 if (!mount) { 12 return document.querySelector('.c-customer-area.o-section'); 13 } 14 15 // Prefer the customer-area section if found near the mount 16 const customerArea = mount.closest('.c-customer-area'); 17 if (customerArea) return customerArea; 18 19 // If the mount is teleported into a popup, grab the page section directly 20 const pageCustomerArea = document.querySelector('.c-customer-area.o-section'); 21 if (pageCustomerArea) return pageCustomerArea; 22 23 // Fallback to any .o-section (except leadgenerator) 24 return mount.closest('.o-section:not(.c-leadgenerator)'); 25 }; 26 27 const getSections = () => document.querySelectorAll('.o-section:not(.c-customer-area):not(.c-leadgenerator), .c-banner'); 28 29 const isAuthed = () => { 30 try { return !!JSON.parse(localStorage.getItem('auth') || '{}').isAuthenticated; } 31 catch { return false; } 32 }; 33 34 const hasCustomerArea = () => document.querySelector('.c-customer-area') !== null; 35 36 const toggleSections = () => { 37 const authed = isAuthed(); 38 getSections().forEach((section) => { 39 section.style.display = authed ? 'none' : ''; 40 }); 41 }; 42 43 const apply = () => { 44 const host = getHost(); 45 if (host) { 46 host.classList.toggle(CLASS, isAuthed()); 47 } 48 if (hasCustomerArea()) { 49 toggleSections(); 50 } 51 }; 52 53 // 1) Initial apply (now + when the mount appears late) 54 if (document.readyState === 'loading') { 55 document.addEventListener('DOMContentLoaded', apply, { once: true }); 56 } else { 57 apply(); 58 } 59 60 // If Vue mounts after DOMContentLoaded, catch it: 61 const mo = new MutationObserver(() => { 62 if (getMount()) { 63 apply(); 64 } 65 }); 66 mo.observe(document.documentElement, { childList: true, subtree: true }); 67 68 // 2) React instantly to your appâs custom events 69 window.addEventListener('oo-login-success', apply); 70 window.addEventListener('oo-logout-success', apply); 71 72 // 3) Cross-tab/local changes 73 window.addEventListener('storage', (e) => { if (e.key === 'auth') apply(); }); 74 75 // 4) Same-tab localStorage updates (optional shim) 76 const _setItem = localStorage.setItem; 77 localStorage.setItem = function (k, v) { 78 _setItem.apply(this, arguments); 79 if (k === 'auth') apply(); 80 }; 81})();
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.