1(function () { 2 'use strict'; 3 4 var config = window.GWDPopupWithAPI || {}; 5 6 function buildPopupApiUrl() { 7 return config.apiUrl || ''; 8 } 9 10 function buildBrandLandingFromApi(data) { 11 var adultData = data && data.data && data.data['18+']; 12 var matchId = adultData && adultData.matchId ? String(adultData.matchId).trim() : ''; 13 var liveId = adultData && adultData.liveId ? String(adultData.liveId).trim() : ''; 14 15 if (!matchId || !liveId) { 16 return ''; 17 } 18 19 return new URL( 20 '/truc-tiep/truc-tiep-bong-da-' + encodeURIComponent(matchId) + '?liveid=' + encodeURIComponent(liveId), 21 window.location.origin 22 ).href; 23 } 24 var POPUP_API_URL = buildPopupApiUrl(); 25 // console.log('[GWD Popup] API URL:', POPUP_API_URL); 26 var popup = document.querySelector('[data-gwd-popup]'); 27 28 if (!popup) { 29 return; 30 } 31 32 var link = popup.querySelector('[data-gwd-popup-link]'); 33 var closeButtons = popup.querySelectorAll('[data-gwd-popup-close]'); 34 var delayMs = Number(config.delayMs || 0); 35 var cooldownMs = Number(config.cooldownMs || 0); 36 var storageKey = config.storageKey || 'gwd_popup_hidden_until'; 37 38 function now() { 39 return Date.now ? Date.now() : new Date().getTime(); 40 } 41 42 function getHiddenUntil() { 43 try { 44 return Number(window.localStorage.getItem(storageKey) || 0); 45 } catch (error) { 46 return 0; 47 } 48 } 49 50 function setCooldown() { 51 if (cooldownMs <= 0) { 52 return; 53 } 54 55 try { 56 window.localStorage.setItem(storageKey, String(now() + cooldownMs)); 57 } catch (error) { 58 // Ignore storage failures so the popup still works in private modes. 59 } 60 } 61 62 function hidePopup() { 63 popup.hidden = true; 64 document.body.classList.remove('gwd-popup-is-open'); 65 } 66 67 function closePopup() { 68 setCooldown(); 69 hidePopup(); 70 } 71 72 function showPopup() { 73 if (getHiddenUntil() > now()) { 74 return; 75 } 76 77 popup.hidden = false; 78 document.body.classList.add('gwd-popup-is-open'); 79 } 80 81 function setPopupLink(url) { 82 if (!link || !url) { 83 return; 84 } 85 86 link.href = url; 87 } 88 89 function getLiveId(value) { 90 var url; 91 92 if (typeof value !== 'string' || !value.trim()) { 93 return ''; 94 } 95 96 try { 97 url = new URL(value, window.location.origin); 98 return url.searchParams.get('liveid') || url.searchParams.get('liveId') || ''; 99 } catch (error) { 100 return ''; 101 } 102 } 103 104 function hasCurrentLiveId(url) { 105 var currentLiveId = getLiveId(window.location.href); 106 var targetLiveId = getLiveId(url); 107 108 return currentLiveId !== '' && targetLiveId !== '' && currentLiveId === targetLiveId; 109 } 110 111 112 function fetchPopupLink() { 113 if (!POPUP_API_URL) { 114 return Promise.resolve(''); 115 } 116 117 return fetch(POPUP_API_URL, { 118 headers: { 119 'Accept': 'application/json' 120 } 121 }) 122 .then(function (response) { 123 if (!response.ok) { 124 throw new Error('Popup API request failed'); 125 } 126 127 return response.json(); 128 }) 129 .then(function (data) { 130 var brandLandingUrl = buildBrandLandingFromApi(data); 131 132 // if (brandLandingUrl) { 133 // console.log('[GWD Popup] BrandLanding URL:', brandLandingUrl); 134 // } else { 135 // console.log('[GWD Popup] BrandLanding URL not found'); 136 // } 137 138 return brandLandingUrl; 139 }) 140 .catch(function (error) { 141 console.log('[GWD Popup] Fetch API failed:', error); 142 return ''; 143 }); 144 } 145 146 Array.prototype.forEach.call(closeButtons, function (button) { 147 button.addEventListener('click', closePopup); 148 149 button.addEventListener('keydown', function (event) { 150 if (event.key === 'Enter' || event.key === ' ') { 151 event.preventDefault(); 152 closePopup(); 153 } 154 }); 155 }); 156 157 if (link) { 158 link.addEventListener('click', function (event) {
159 setCooldown(); 160 161 if (!link.href || link.getAttribute('href') === '#') { 162 event.preventDefault(); 163 } 164 }); 165 } 166 167 document.addEventListener('keydown', function (event) { 168 if (event.key === 'Escape' && !popup.hidden) { 169 closePopup(); 170 } 171 }); 172 173 var shouldSkipPopup = false; 174 175 fetchPopupLink().then(function (url) { 176 if (!url) { 177 // console.log('[GWD Popup] BrandLanding is empty, skip popup'); 178 shouldSkipPopup = true; 179 return; 180 } 181 182 if (hasCurrentLiveId(url)) { 183 // console.log('[GWD Popup] Current liveId matches BrandLanding, skip popup:', url); 184 shouldSkipPopup = true; 185 return; 186 } 187 188 setPopupLink(url); 189 }).finally(function () { 190 if (shouldSkipPopup) { 191 return; 192 } 193 194 if (getHiddenUntil() > now()) { 195 console.log('[GWD Popup] Popup is hidden by localStorage until:', new Date(getHiddenUntil())); 196 return; 197 } 198 199 window.setTimeout(showPopup, delayMs); 200 }); 201})();
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.