PageSourceSearch

https://eadplataforma.com/assets/js/whats-routing.js?v=1788559996

js eadplataforma.com collected 2026-09-24 22:12:37 UTC 3,364 bytes, 140 lines download raw bytes

1// Persiste consultor do /whats/ e /agenda/ no localStorage (30 dias) e reutiliza em novos cliques.
2(function (window) {
3  var KEY = 'ead_whats_consultor';
4  var PARAM = 'c';
5  var MAX_AGE = 30 * 24 * 60 * 60 * 1000;
6
7  function readStored() {
8    try {
9      var raw = localStorage.getItem(KEY);
10      if (!raw) {
11        return null;
12      }
13
14      var data = JSON.parse(raw);
15      if (!data || !data.exp) {
16        return null;
17      }
18
19      if (Date.now() > parseInt(data.exp, 10)) {
20        localStorage.removeItem(KEY);
21        return null;
22      }
23
24      var phone = data.phone ? String(data.phone) : '';
25      var username = data.username ? String(data.username) : '';
26      if (!phone && !username) {
27        return null;
28      }
29
30      return { phone: phone, username: username };
31    } catch (e) {
32      return null;
33    }
34  }
35
36  function isWhatsHref(href) {
37    return !!href && href.indexOf('/whats') !== -1;
38  }
39
40  function isDirectWhatsConsultoraHref(href) {
41    return /\/whats\/[0-9+]{10,16}/.test(href || '');
42  }
43
44  function isAgendaHref(href) {
45    return !!href && href.indexOf('/agenda') !== -1;
46  }
47
48  function hasConsultorParam(href) {
49    return /[?&]c=/.test(href);
50  }
51
52  function appendConsultor(href, value) {
53    if (!value) {
54      return href;
55    }
56
57    var url;
58    try {
59      url = new URL(href, window.location.origin);
60    } catch (e) {
61      return href;
62    }
63
64    if (url.pathname.indexOf('/whats') === -1 && url.pathname.indexOf('/agenda') === -1) {
65      return href;
66    }
67
68    url.searchParams.set(PARAM, value);
69    return url.pathname + url.search + url.hash;
70  }
71
72  function consultorValueForHref(href, stored) {
73    if (!stored) {
74      return '';
75    }
76    if (isAgendaHref(href)) {
77      return stored.username || stored.phone || '';
78    }
79    return stored.phone || stored.username || '';
80  }
81
82  function decorateLinks() {
83    var stored = readStored();
84    if (!stored) {
85      return;
86    }
87
88    document.querySelectorAll('a[href]').forEach(function (anchor) {
89      var href = anchor.getAttribute('href') || '';
90      if ((!isWhatsHref(href) && !isAgendaHref(href)) || hasConsultorParam(href) || isDirectWhatsConsultoraHref(href)) {
91        return;
92      }
93
94      var value = consultorValueForHref(href, stored);
95      if (!value) {
96        return;
97      }
98
99      anchor.setAttribute('href', appendConsultor(href, value));
100    });
101  }
102
103  document.addEventListener('click', function (event) {
104    var anchor = event.target.closest('a[href]');
105    if (!anchor) {
106      return;
107    }
108
109    var href = anchor.getAttribute('href') || '';
110    if ((!isWhatsHref(href) && !isAgendaHref(href)) || hasConsultorParam(href) || isDirectWhatsConsultoraHref(href)) {
111      return;
112    }
113
114    var stored = readStored();
115    if (!stored) {
116      return;
117    }
118
119    var value = consultorValueForHref(href, stored);
120    var nextHref = appendConsultor(href, value);
121    if (nextHref !== href) {
122      anchor.setAttribute('href', nextHref);
123    }
124  }, true);
125
126  window.EadWhats = {
127    readStored: function () {
128      var stored = readStored();
129      return stored ? stored.phone : null;
130    },
131    decorateLinks: decorateLinks,
132    appendConsultor: appendConsultor
133  };
134
135  if (document.readyState === 'loading') {
136    document.addEventListener('DOMContentLoaded', decorateLinks);
137  } else {
138    decorateLinks();
139  }
140})(window);

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.