PageSourceSearch

https://lunter.com/wp-content/cache/wpfc-minified/de90vcw9/2rtyu.js

js lunter.com collected 2026-10-10 01:00:49 UTC 4,559 bytes, 132 lines download raw bytes

1// source --> https://lunter.com/wp-content/themes/lunter/assets/js/language-popup.js?ver=1777635192 
2(function () {
3    'use strict';
4
5    var PREF_COOKIE = 'lunter_lang_pref';
6    var COOKIE_DAYS = 90;
7    var TAB_REDIRECT_KEY = 'lunter_lang_redirected';
8
9    function isTabRedirectDone() {
10        try { return sessionStorage.getItem(TAB_REDIRECT_KEY) === '1'; }
11        catch (e) { return false; }
12    }
13
14    function markTabRedirectDone() {
15        try { sessionStorage.setItem(TAB_REDIRECT_KEY, '1'); }
16        catch (e) {}
17    }
18
19    function readCookie(name) {
20        var prefix = name + '=';
21        var parts = document.cookie ? document.cookie.split(';') : [];
22        for (var i = 0; i < parts.length; i++) {
23            var c = parts[i].replace(/^\s+/, '');
24            if (c.indexOf(prefix) === 0) {
25                return decodeURIComponent(c.substring(prefix.length));
26            }
27        }
28        return '';
29    }
30
31    function writeCookie(name, value, days) {
32        var secure = location.protocol === 'https:' ? '; Secure' : '';
33        var expires = '';
34        if (days) {
35            var d = new Date();
36            d.setTime(d.getTime() + days * 24 * 60 * 60 * 1000);
37            expires = '; expires=' + d.toUTCString();
38        }
39        document.cookie = name + '=' + encodeURIComponent(value) +
40            expires + '; path=/; SameSite=Lax' + secure;
41    }
42
43    var data = (typeof LunterLangData !== 'undefined') ? LunterLangData : null;
44    var current = data && data.current ? String(data.current).toLowerCase() : '';
45    var urls = (data && data.urls) ? data.urls : {};
46    var pref = readCookie(PREF_COOKIE).toLowerCase();
47
48    // Redirect to the preferred language only on the first load of each tab.
49    // sessionStorage is scoped per tab, so opening a new tab triggers the
50    // check again, but in-tab navigation (manual switches via header switcher
51    // or anything else) is left alone.
52    if (current && !isTabRedirectDone()) {
53        markTabRedirectDone();
54        if (pref && pref !== current && urls[pref]) {
55            location.replace(urls[pref]);
56            return;
57        }
58    }
59
60    function initPopup() {
61        var popup = document.getElementById('lang-popup');
62        if (!popup) return;
63
64        // Preference already set (chosen or dismissed) - skip popup.
65        if (pref) return;
66
67        popup.removeAttribute('hidden');
68        void popup.offsetWidth;
69        popup.classList.add('is-visible');
70
71        function dismiss() {
72            writeCookie(PREF_COOKIE, current, COOKIE_DAYS);
73            popup.classList.remove('is-visible');
74            setTimeout(function () {
75                popup.setAttribute('hidden', '');
76            }, 300);
77        }
78
79        var closeBtn = popup.querySelector('.lang-popup__close');
80        if (closeBtn) {
81            closeBtn.addEventListener('click', dismiss);
82        }
83
84        var backdrop = popup.querySelector('.lang-popup__backdrop');
85        if (backdrop) {
86            backdrop.addEventListener('click', dismiss);
87        }
88
89        var links = popup.querySelectorAll('.lang-popup__link');
90        for (var i = 0; i < links.length; i++) {
91            links[i].addEventListener('click', function (e) {
92                var lang = (this.getAttribute('data-lang') || '').toLowerCase();
93                writeCookie(PREF_COOKIE, lang, COOKIE_DAYS);
94                if (lang && lang === current) {
95                    e.preventDefault();
96                    dismiss();
97                }
98            });
99        }
100
101        document.addEventListener('keydown', function (e) {
102            if (e.key === 'Escape' || e.keyCode === 27) {
103                dismiss();
104            }
105        });
106    }
107
108    function initSwitcher() {
109        // Manual language switching via the header switcher updates the stored preference,
110        // so the next session lands on whatever the user last chose.
111        var switcherLinks = document.querySelectorAll('.language-switcher a[data-lang]');
112        for (var i = 0; i < switcherLinks.length; i++) {
113            switcherLinks[i].addEventListener('click', function () {
114                var lang = (this.getAttribute('data-lang') || '').toLowerCase();
115                if (lang) {
116                    writeCookie(PREF_COOKIE, lang, COOKIE_DAYS);
117                }
118            });
119        }
120    }
121
122    function init() {
123        initPopup();
124        initSwitcher();
125    }
126
127    if (document.readyState === 'loading') {
128        document.addEventListener('DOMContentLoaded', init);
129    } else {
130        init();
131    }
132})();

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.