1jQuery(document).ready(function($) { 2 // Lưu interval riêng cho từng button 3 let countdownIntervals = { 4 'tan_thu': null, 5 'CHECK_IN': null 6 }; 7 8 let currentCode = { 9 'tan_thu': '', 10 'CHECK_IN': '' 11 }; 12 13 // Debug: Kiá»m tra giá trá» countdown từ server 14 console.log('ð§ Debug - Countdown config:', giftcodeAPI.countdown); 15 console.log('ð§ Debug - Countdown Checkin config:', giftcodeAPI.countdown_checkin); 16 17 // ⨠Tá»± Äá»ng bắt Äầu countdown nếu URL có parameter auto_checkin 18 const urlParams = new URLSearchParams(window.location.search); 19 if (urlParams.get('auto_checkin') === '1') { 20 console.log('ð¯ Detected auto_checkin=1 parameter - Auto-triggering countdown'); 21 22 // Äợi 2 giây sau khi trang load 23 setTimeout(function() { 24 const $checkinBtn = $('#checkin-btn-post'); 25 if ($checkinBtn.length) { 26 console.log('â±ï¸ Starting scroll after 2s delay'); 27 28 // TÃnh toán vá» trà Äá» button nằm giữa mà n hình 29 const buttonTop = $checkinBtn.offset().top; 30 const buttonHeight = $checkinBtn.outerHeight(); 31 const windowHeight = $(window).height(); 32 33 // Vá» trà scroll = vá» trà button - (chiá»u cao mà n hình / 2) + (chiá»u cao button / 2) 34 const scrollPosition = buttonTop - (windowHeight / 2) + (buttonHeight / 2); 35 36 console.log('ð Button position:', buttonTop); 37 console.log('ð Window height:', windowHeight); 38 console.log('ð¯ Scroll to position:', scrollPosition); 39 40 // Scroll Äến vá» trà giữa mà n hình trong 500ms 41 $('html, body').animate({ 42 scrollTop: scrollPosition 43 }, 500, function() { 44 // Callback: Chạy sau khi scroll xong 45 console.log('â Scroll complete - Auto-clicking button'); 46 47 // Tá»± Äá»ng click button ngay sau khi scroll xong 48 setTimeout(function() { 49 $checkinBtn.trigger('click'); 50 }, 200); // Chá» 200ms cho mượt 51 }); 52 } 53 }, 1500); // Chá» 1.5 giây trưá»c khi bắt Äầu scroll 54 } 55 56 // Xá» lý khi click button - áp dụng cho cả 2 buttons 57 $('body').on('click', '.giftcode-button', function(e) { 58 const $btn = $(this); 59 60 // Nếu là link (button Äiá»m danh á» homepage), cho phép chuyá»n hưá»ng 61 if ($btn.is('a')) { 62 console.log('ð Link detected - Allow navigation to:', $btn.attr('href')); 63 return true; // Cho phép chuyá»n hưá»ng 64 } 65 66 e.preventDefault(); // Chá» prevent default cho button tháºt 67 68 const type = $btn.data('type'); // Lấy type từ data attribute 69 70 // Nếu không có type, không là m gì 71 if (!type) { 72 console.warn('â ï¸ Button không có data-type attribute'); 73 return; 74 } 75 76 // Chá»n error div phù hợp 77 const $errorDiv = type === 'CHECK_IN' ? $('#giftcode-error-checkin') : $('#giftcode-error'); 78 79 // Nếu Äã có code cho button nà y, thá»±c hiá»n copy 80 if (currentCode[type]) { 81 copyCode(currentCode[type]); 82 return; 83 } 84 85 // Nếu button nà y Äang countdown, không là m gì cả 86 if (countdownIntervals[type]) { 87 return; 88 } 89 90 // Lấy countdown tương ứng vá»i button type 91 let countdownSeconds; 92 if (type === 'CHECK_IN') { 93 countdownSeconds = parseInt(giftcodeAPI.countdown_checkin) || 15; 94 } else { 95 countdownSeconds = parseInt(giftcodeAPI.countdown) || 15; 96 } 97 98 // Debug log 99 console.log('â±ï¸ Countdown seconds:', countdownSeconds); 100 console.log('ð¯ Button type:', type); 101 102 // Validate countdown 103 if (countdownSeconds < 0 || countdownSeconds > 60) { 104 countdownSeconds = 15; 105 } 106 107 // Bắt Äầu countdown 108 let seconds = countdownSeconds; 109 const originalText = $btn.html(); 110 $btn.prop('disabled', true); 111 $errorDiv.hide(); 112 113 const updateCountdown = () => { 114 $btn.html('â³ Vui lòng chá» ' + seconds + ' giây'); 115 seconds--; 116 117 if (seconds < 0) { 118 // Clear interval cá»§a button nà y 119 clearInterval(countdownIntervals[type]); 120 countdownIntervals[type] = null; 121 fetchGiftcode(); 122 } 123 }; 124 125 updateCountdown(); 126 // Lưu interval riêng cho button nà y 127 countdownIntervals[type] = setInterval(updateCountdown, 1000); 128 129 // Gá»i API Äá» lấy giftcode 130 function fetchGiftcode() { 131 // Lấy service URL từ data attribute (nếu có) 132 const serviceUrl = $btn.data('service-url'); 133 134 // Chuẩn bá» URL vá»i query params 135 let apiUrl = giftcodeAPI.url; 136 const params = []; 137 138 if (serviceUrl) { 139 params.push('service_url=' + encodeURIComponent(serviceUrl)); 140 } 141 142 // Thêm type parameter 143 if (type) { 144 params.push('type=' + encodeURIComponent(type)); 145 } 146 147 if (params.length > 0) { 148 apiUrl += '?' + params.join('&'); 149 } 150 151 console.log('ð API URL:', apiUrl); 152 153 $.ajax({ 154 url: apiUrl, 155 method: 'GET', 156 beforeSend: function(xhr) { 157 xhr.setRequestHeader('X-WP-Nonce', giftcodeAPI.nonce); 158 }, 159 success: function(response) { 160 console.log('Response từ API:', response); 161 162 if (response.success && response.data) { 163 // Lấy code từ response 164 let code = ''; 165 166 // Kiá»m tra các trưá»ng hợp khác nhau cá»§a response 167 if (typeof response.data === 'object') { 168 code = response.data.code || response.data.giftcode || response.data.gift_code || ''; 169 170 // Nếu có nested data 171 if (!code && response.data.data) { 172 code = response.data.data.code || response.data.data.giftcode || ''; 173 } 174 } else if (typeof response.data === 'string') { 175 code = response.data; 176 } 177 178 if (code) { 179 currentCode[type] = code; 180 $btn.html(currentCode[type] + ' <span class="copy-icon">ð</span>'); 181 $btn.addClass('with-code'); 182 $btn.prop('disabled', false); 183 } else { 184 showError('Giftcode Äã hết. Vui lòng liên há» CSKH Äá» ÄÆ°á»£c há» trợ', $errorDiv); 185 $btn.html(originalText); 186 $btn.prop('disabled', false); 187 } 188 } else { 189 showError(response.message || 'Giftcode Äã hết. Vui lòng liên há» CSKH Äá» ÄÆ°á»£c há» trợ', $errorDiv); 190 $btn.html(originalText); 191 $btn.prop('disabled', false); 192 } 193 }, 194 error: function(xhr, status, error) { 195 console.error('Error:', error); 196 showError('Không thá» kết ná»i Äến server!', $errorDiv); 197 $btn.html(originalText); 198 $btn.prop('disabled', false); 199 } 200 }); 201 } 202 }); 203 204 /** 205 * Copy code và o clipboard 206 */ 207 function copyCode(code) { 208 if (code) { 209 // Thá» dùng Clipboard API 210 if (navigator.clipboard && navigator.clipboard.writeText) { 211 navigator.clipboard.writeText(code).then(function() { 212 alert('Chúc mừng bạn Äã nháºn Code và Copy thà nh công, má»i bạn và o game Äá» nháºp Code.'); 213 }).catch(function(err) { 214 fallbackCopy(code); 215 }); 216 } else { 217 fallbackCopy(code); 218 } 219 } 220 } 221 222 /** 223 * Fallback copy method 224 */ 225 function fallbackCopy(code) { 226 const tempInput = $('<input>'); 227 $('body').append(tempInput); 228 tempInput.val(code).select(); 229 document.execCommand('copy'); 230 tempInput.remove(); 231 alert('Chúc mừng bạn Äã nháºn Code và Copy thà nh công, má»i bạn và o game Äá» nháºp Code.'); 232 } 233 234 /** 235 * Hiá»n thá» lá»i 236 */ 237 function showError(message, $errorDiv) { 238 if (!$errorDiv) { 239 $errorDiv = $('#giftcode-error'); 240 } 241 $errorDiv.text(message).show(); 242 } 243});
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.