PageSourceSearch

https://lc79.xyz/wp-content/plugins/gc-plugin/assets/js/frontend.js?ver=2.1-15-1791174739

js lc79.xyz collected 2026-10-05 04:32:38 UTC 9,522 bytes, 243 lines download raw bytes

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.