PageSourceSearch

https://www.kientruc.com/js/congdong.js?v=1750597781

js kientruc.com collected 2026-10-08 10:13:53 UTC 7,148 bytes, 200 lines download raw bytes

1window.congdong_save = function (el) {
2    el.setAttribute('disabled', 'disabled');
3    if (window._logID != '0') {
4        let id = el.getAttribute('data-has-save-congdong') * 1;
5        let isSaved = el.getAttribute('data-save-congdong') === 'true';
6        // Đảo ngược trạng thái like ngay lập tức
7        el.setAttribute('data-save-congdong', isSaved ? 'false' : 'true');
8
9        $.get('/congdong/savepost', { id_post: id }, function (json) {
10            el.removeAttribute('disabled');
11            if (json.data * 1 == 1) {
12                el.setAttribute('data-save-congdong', 'true');
13                _addUniqueItemsToLocalStorage(window._logID, 'save_congdong', [id]);
14            } else {
15                el.setAttribute('data-save-congdong', 'false');
16                _removeUniqueItemsFromLocalStorage(window._logID, 'save_congdong', [id]);
17            }
18        });
19    } else {
20        _callModalLogin(el);
21        el.removeAttribute('disabled');
22    }
23};
24
25// Reusable function to fetch and cache data
26window.congdong_fetchAndCacheData = function (url, cacheKey, cacheExpiryKey, cacheExpiryTime, page = 1, append = false, callback) {
27    let now = Date.now();
28    let cachedData = JSON.parse(localStorage.getItem(cacheKey) || '[]');
29    let cacheExpiry = localStorage.getItem(cacheExpiryKey) || 0;
30    let cachePage = 'congDongPageCache';
31
32    if (now < cacheExpiry && cachedData.length > 0 && !append) {
33        callback(cachedData);
34    } else {
35        localStorage.setItem(cachePage, page);
36        $.get(`${url}?page=${page}`, function (res) {
37            let newData = res.data.items.map(item => ({
38                src: item.src,
39                alt: item.alt,
40                id: item.id,
41                post_id: item.post_id
42            }));
43            if (!append) {
44                localStorage.setItem(cacheKey, JSON.stringify(newData));
45                localStorage.setItem(cacheExpiryKey, now + cacheExpiryTime);
46                callback(newData);
47            } else {
48                let updatedCache = [...cachedData, ...newData];
49                localStorage.setItem(cacheKey, JSON.stringify(updatedCache));
50                callback(newData);
51            }
52        });
53    }
54};
55
56window.congdong_loadmore = function () {
57    let renderImages = (images) => {
58        let html = images.slice(0, 4).map(img => `
59            <div class="w-50 border">
60                <img class="cursor-pointer" src="${img.src}" alt="${img.alt}" onclick="congdong_photo(this,${img.id},${img.post_id})">
61            </div>
62        `).join('');
63        document.getElementById('js-render-4-img').innerHTML += html;
64    };
65
66    window.congdong_fetchAndCacheData(
67        '/congdong/photo',
68        'congDongThumbsCache',
69        'congDongThumbsCacheExpiry',
70        5 * 60 * 1000,
71        1,
72        false,
73        function (data) {
74            document.getElementById('js-render-more-btn').removeAttribute('disabled');
75            renderImages(data);
76        }
77    );
78};
79
80window.congdong_thumbs = function (el) {
81    let idmodal = 'congDongThumbsModal';
82    let cacheKey = 'congDongThumbsCache';
83    let cachePage = 'congDongPageCache';
84    let cacheExpiryKey = 'congDongThumbsCacheExpiry';
85    let cacheExpiryTime = 5 * 60 * 1000; // 5 minutes
86
87    let renderImages = (images) => {
88        let html = images.map(img => `
89            <div class="col-3 border">
90                <img class="cursor-pointer" src="${img.src}" alt="${img.alt}" onclick="congdong_photo(this,${img.id},${img.post_id})">
91            </div>
92        `).join('');
93        document.getElementById('congDongThumbsModalRow').innerHTML += html;
94    };
95
96    let html = `
97        <div class="modal-header">
98            <h5 class="modal-title" id="exampleModalLabel">Tất cả các file</h5>
99        </div>
100        <div class="p-3">
101            <div class="row" id="congDongThumbsModalRow"></div>
102        </div>
103        <div class="modal-footer">
104            <button type="button" class="btn btn-secondary" id="loadMoreThumbs" data-page="2">Load thêm</button>
105        </div>
106    `;
107    _createModal(idmodal, '', html, '', 'modal-xl');
108
109    window.congdong_fetchAndCacheData(
110        '/congdong/photo',
111        cacheKey,
112        cacheExpiryKey,
113        cacheExpiryTime,
114        1,
115        false,
116        function (data) {
117            renderImages(data);
118        });
119
120    document.getElementById('loadMoreThumbs').onclick = function () {
121        let nextPage = localStorage.getItem(cachePage) * 1 + 1;
122        window.congdong_fetchAndCacheData(
123            '/congdong/photo',
124            cacheKey,
125            cacheExpiryKey,
126            cacheExpiryTime,
127            nextPage,
128            true,
129            function (data) {
130                renderImages(data);
131            });
132    };
133};
134
135window.thiscurrent = 0;
136
137window.congdong_photo = function (el, photo_id, post_id) {
138    let idmodal = 'congDongPhotoModal';
139    let cacheKey = 'congDongThumbsCache';
140    let cachedData = JSON.parse(localStorage.getItem(cacheKey) || '[]');
141
142    let photo = null;
143    if (post_id === -1) {
144        photo = window.thiscurrent > 0 ? cachedData[window.thiscurrent - 1] : null;
145        window.thiscurrent -= 1;
146    } else if (post_id === -2) {
147        photo = window.thiscurrent < cachedData.length - 1 ? cachedData[window.thiscurrent + 1] : null;
148        window.thiscurrent += 1;
149    } else {
150        // Find the photo in the cache
151        let currentIndex = cachedData.findIndex(item => item.id === photo_id);
152        photo = cachedData[currentIndex];
153        window.thiscurrent = currentIndex;
154    }
155
156    if(photo === null) {
157        let cacheKey = 'congDongThumbsCache';
158        let cachePage = 'congDongPageCache';        
159        let cacheExpiryKey = 'congDongThumbsCacheExpiry';
160        let cacheExpiryTime = 5 * 60 * 1000; // 5 minutes
161
162        let nextPage = localStorage.getItem(cachePage) * 1 + 1;
163        window.congdong_fetchAndCacheData(
164        '/congdong/photo',
165        cacheKey,
166        cacheExpiryKey,
167        cacheExpiryTime,
168        nextPage,
169        false,
170        function () {});
171    }
172
173    // Check if the modal already matches the post_id
174    let existingPostElement = document.getElementById('id_post_chung');
175    if (existingPostElement && parseInt(existingPostElement.getAttribute('data-id')) === post_id) {
176        // Only update the photo
177        if (photo) {
178            let photoElement = document.getElementById('js-discuss-photo-img');
179            if (photoElement) {
180                photoElement.src = photo.src;
181            }
182        }
183    } else {
184        // Fetch post details and show modal
185        $.get('/congdong/detail-modal?id=' + post_id, function (res) {
186            let html = res;
187            _createModal(idmodal, '', html, '', 'modal-xl');
188            _renderLike();
189            _renderSaveDisccuss();
190
191            // Insert the photo into the element with ID js-discuss-photo-img
192            if (photo) {
193                let photoElement = document.getElementById('js-discuss-photo-img');
194                if (photoElement) {
195                    photoElement.src = photo.src;
196                }
197            }
198        });
199    }
200};

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.