PageSourceSearch

https://xmacna.ai/i18n/language-switcher.js

js xmacna.ai collected 2026-10-05 13:23:13 UTC 2,795 bytes, 55 lines download raw bytes

1/* Shared document navigation for raw HTML pages; ordinary links also work without JS. */
2(function () {
3  'use strict';
4  var pending = new URL(location.href).searchParams.get('_xm_locale');
5  if (/^(pt-br|en|es)$/.test(pending || '')) {
6    document.cookie = 'xmacna_locale=' + pending + '; Path=/; Max-Age=31536000; SameSite=Lax' + (location.protocol === 'https:' ? '; Secure' : '');
7    var clean = new URL(location.href);
8    clean.searchParams.delete('_xm_locale');
9    history.replaceState(history.state, '', clean.pathname + clean.search + clean.hash);
10  }
11  var locale = document.body.dataset.xmLocale || 'pt-br';
12  function localizeLinks(node) {
13    var elements = [];
14    if (node.nodeType !== 1) return;
15    if (node.matches('a[href]')) elements.push(node);
16    node.querySelectorAll('a[href]').forEach(function (a) { elements.push(a); });
17    elements.forEach(function (a) {
18      if (a.hasAttribute('data-xm-locale')) return;
19      var raw = a.getAttribute('href');
20      if (!raw || raw.charAt(0) === '#') return;
21      var url = new URL(raw, location.origin);
22      if (url.origin !== location.origin && url.hostname !== 'xmacna.ai') return;
23      var target = (window.__xmRoutes || {})[url.pathname];
24      if (target && target !== url.pathname) a.setAttribute('href', target + url.search + url.hash);
25    });
26  }
27  localizeLinks(document.body);
28  new MutationObserver(function (records) {
29    records.forEach(function (record) {
30      record.addedNodes.forEach(localizeLinks);
31      if (record.type === 'attributes') localizeLinks(record.target);
32    });
33  }).observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['href'] });
34  var labels = document.querySelectorAll('[data-xm-locale]');
35  labels.forEach(function (link) {
36    if (link.tagName !== 'A') return;
37    var target = new URL(link.href, location.origin);
38    var current = new URL(location.href);
39    current.searchParams.forEach(function (value, key) {
40      if (key !== 'lang') target.searchParams.append(key, value);
41    });
42    target.hash = current.hash;
43    link.href = target.pathname + target.search + target.hash;
44    link.addEventListener('click', function () {
45      document.cookie = 'xmacna_locale=' + link.dataset.xmLocale + '; Path=/; Max-Age=31536000; SameSite=Lax' + (location.protocol === 'https:' ? '; Secure' : '');
46    });
47  });
48  // Country is a routing hint; do not silently rewrite the contact's phone number.
49  document.querySelectorAll('input[type="tel"], input[inputmode="tel"]').forEach(function (input) {
50    if (locale !== 'pt-br') input.placeholder = locale === 'es' ? '+34 612 345 678' : '+1 212 555 0123';
51    input.autocomplete = 'tel';
52  });
53  window.dataLayer = window.dataLayer || [];
54  window.dataLayer.push({ site_locale: locale });
55})();

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.