1(function () { 2 'use strict'; 3 4 var cfg = window.CONJUR_ACCOUNT || {}; 5 if (!cfg.loggedIn || !cfg.user) return; 6 7 var first = String(cfg.user.firstName || cfg.user.fullName || 'Usuário') 8 .trim() 9 .split(/\s+/)[0]; 10 first = first.charAt(0).toUpperCase() + first.slice(1).toLowerCase(); 11 var email = (cfg.user.email || '').trim(); 12 var greeting = 'Bem-vindo, ' + first; 13 14 function looksLikeLoginLink(a) { 15 if (!a || !a.getAttribute) return false; 16 var raw = (a.getAttribute('href') || '').toLowerCase(); 17 var text = ((a.textContent || '') + ' ' + (a.getAttribute('aria-label') || '')).toLowerCase().trim(); 18 19 if (raw.indexOf('action=logout') !== -1 || raw.indexOf('cma_logout') !== -1) return false; 20 if (/sair|logout|log\s*out/.test(text)) return false; 21 22 if (raw.indexOf('minha-area/entrar') !== -1) return true; 23 if (raw.indexOf('wp-login.php') !== -1 && raw.indexOf('action=') === -1) return true; 24 if (raw === '#' && /^(login|entrar|acessar)$/.test(text)) return true; 25 if (/^(login|entrar|acessar)$/.test(text)) return true; 26 if (text.indexOf('login') !== -1 && text.length < 24) return true; 27 return false; 28 } 29 30 function closeAll(except) { 31 document.querySelectorAll('.cma-account.is-open').forEach(function (el) { 32 if (el !== except) el.classList.remove('is-open'); 33 }); 34 } 35 36 function setButtonLabel(btn) { 37 var textEl = btn.querySelector('.elementor-button-text'); 38 if (textEl) { 39 textEl.textContent = greeting; 40 return; 41 } 42 // Fallback: botão sem estrutura Elementor 43 btn.innerHTML = 44 '<span class="cma-account__greeting">' + 45 escapeHtml(greeting) + 46 '</span><span class="cma-account__caret" aria-hidden="true"></span>'; 47 } 48 49 function buildMenu(sourceLink) { 50 var wrap = document.createElement('div'); 51 wrap.className = 'cma-account'; 52 53 // Reaproveita o markup/classes do Login (= mesmo visual do Anuncie). 54 var btn; 55 if (sourceLink && sourceLink.cloneNode) { 56 btn = sourceLink.cloneNode(true); 57 btn.setAttribute('href', '#'); 58 btn.setAttribute('role', 'button'); 59 btn.removeAttribute('target'); 60 btn.removeAttribute('rel'); 61 btn.classList.add('cma-account__toggle'); 62 setButtonLabel(btn); 63 // Seta via CSS (::after) para não quebrar o alinhamento Ãcone/texto do Elementor. 64 } else { 65 btn = document.createElement('button'); 66 btn.type = 'button'; 67 btn.className = 'cma-account__toggle cma-account__toggle--fallback'; 68 setButtonLabel(btn); 69 } 70 71 btn.setAttribute('aria-expanded', 'false'); 72 btn.setAttribute('aria-haspopup', 'true'); 73 btn.setAttribute('aria-label', greeting); 74 75 var menu = document.createElement('div'); 76 menu.className = 'cma-account__menu'; 77 menu.setAttribute('role', 'menu'); 78 var showMyArea = !!(cfg.user.isReader && !cfg.user.isStaff); 79 var linksHtml = showMyArea 80 ? '<div class="cma-account__links">' + 81 '<a role="menuitem" href="' + 82 escapeAttr(cfg.dashboardUrl || '/minha-area') + 83 '">Dashboard</a>' + 84 '<a role="menuitem" href="' + 85 escapeAttr(cfg.profileUrl || '/minha-area/perfil') + 86 '">Meu perfil</a>' + 87 '</div>' 88 : ''; 89 90 menu.innerHTML = 91 '<div class="cma-account__identity">' + 92 '<strong class="cma-account__name">' + 93 escapeHtml(first) + 94 '</strong>' + 95 (email ? '<span class="cma-account__email">(' + escapeHtml(email) + ')</span>' : '') + 96 '</div>' + 97 linksHtml + 98 '<div class="cma-account__footer">' + 99 '<a role="menuitem" href="' + 100 escapeAttr(cfg.logoutUrl || '#') + 101 '">Sair</a>' + 102 '</div>'; 103 104 btn.addEventListener('click', function (ev) { 105 ev.preventDefault(); 106 ev.stopPropagation(); 107 var open = !wrap.classList.contains('is-open'); 108 closeAll(wrap); 109 wrap.classList.toggle('is-open', open); 110 btn.setAttribute('aria-expanded', open ? 'true' : 'false'); 111 }); 112 113 wrap.appendChild(btn); 114 wrap.appendChild(menu); 115 return wrap; 116 } 117 118 function matchNeighborButtonSize(btn) { 119 var scope = 120 btn.closest('.elementor-widget-wrap, .elementor-container, .elementor-section, header') || 121 document; 122 var buttons = scope.querySelectorAll('a.elementor-button, .elementor-button'); 123 var ref = null; 124 buttons.forEach(function (el) { 125 if (el === btn || el.closest('.cma-account')) return; 126 var t = (el.textContent || '').replace(/\s+/g, ' ').trim().toLowerCase(); 127 if (t === 'anuncie' || (t.indexOf('anuncie') === 0 && t.length < 24)) { 128 ref = el; 129 } 130 }); 131 if (!ref) return; 132 var cs = window.getComputedStyle(ref); 133 btn.style.boxSizing = 'border-box'; 134 btn.style.height = cs.height; 135 btn.style.minHeight = cs.height; 136 btn.style.paddingTop = cs.paddingTop; 137 btn.style.paddingBottom = cs.paddingBottom; 138 btn.style.lineHeight = cs.lineHeight; 139 btn.style.fontSize = cs.fontSize; 140 } 141 142 function replaceLoginLink(a) { 143 if (!a || a.dataset.cmaAccountBound) return; 144 a.dataset.cmaAccountBound = '1'; 145 146 var menu = buildMenu(a); 147 if (a.parentElement) { 148 a.parentElement.replaceChild(menu, a); 149 } 150 var btn = menu.querySelector('.cma-account__toggle'); 151 if (btn) { 152 requestAnimationFrame(function () { 153 matchNeighborButtonSize(btn); 154 }); 155 } 156 } 157 158 function escapeHtml(str) { 159 return String(str || '') 160 .replace(/&/g, '&') 161 .replace(/</g, '<') 162 .replace(/>/g, '>') 163 .replace(/"/g, '"'); 164 } 165 166 function escapeAttr(str) { 167 return escapeHtml(str).replace(/'/g, '''); 168 } 169 170 function run() { 171 document.querySelectorAll('a[href]').forEach(function (a) { 172 if (looksLikeLoginLink(a) && !a.closest('.cma-account')) { 173 replaceLoginLink(a); 174 } 175 }); 176 } 177 178 document.addEventListener('click', function () { 179 closeAll(null); 180 }); 181 182 document.addEventListener('keydown', function (ev) { 183 if (ev.key === 'Escape') closeAll(null); 184 }); 185 186 if (document.readyState === 'loading') { 187 document.addEventListener('DOMContentLoaded', run); 188 } else { 189 run(); 190 } 191 setTimeout(run, 400); 192 setTimeout(run, 1200); 193})();
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.