PageSourceSearch

https://sc.gov/modules/custom/scgov/js/js-display-username.js?v=1.x

js sc.gov collected 2026-09-24 06:55:58 UTC 1,609 bytes, 49 lines download raw bytes

1(function (Drupal, once) {
2  Drupal.behaviors.scgovDisplayUsername = {
3    attach: function (context) {
4      const els = once('scgovDisplayUsername', '.js-display-username', context);
5      if (!els.length) return;
6
7      const key = 'scgov_display_username';
8
9      // If cached in this tab session, use it and stop.
10      const cached = sessionStorage.getItem(key);
11      if (cached) {
12        els.forEach(el => { el.textContent = cached; });
13        return;
14      }
15
16      // Fetch once per tab session.
17      fetch(Drupal.url('scgov/display-username'), {
18        credentials: 'same-origin',
19        headers: { 'X-Requested-With': 'XMLHttpRequest' }
20      })
21        .then(res => {
22          // If not authenticated (timeout or anon), ensure cache is cleared.
23          if (res.status === 204 || res.status === 401 || res.status === 403) {
24            sessionStorage.removeItem(key);
25            return '';
26          }
27          return res.ok ? res.text() : '';
28        })
29        .then(name => {
30          if (!name) return;
31          sessionStorage.setItem(key, name);
32          els.forEach(el => { el.textContent = name; });
33        })
34        .catch(() => {
35          // Silent fail: fallback label remains.
36        });
37
38      // Clear cached name when user clicks Logout.
39      // (Works for the common flow; Okta remaining logged in is okay.)
40      document.addEventListener('click', (e) => {
41        const logoutLink = e.target.closest('a[href*="/user/logout"]');
42        if (logoutLink) {
43          sessionStorage.removeItem(key);
44        }
45      }, { once: true });
46    }
47  };
48})(Drupal, once);
49

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.