1$(document).ready(function() { 2 var jsonData; 3 var currentIndex = 0; 4 var itemsPerPage = 24; 5 var item = ""; 6 var dataLength = 0; 7 8 // Hà m trá»n ngẫu nhiên mảng (Fisher-Yates shuffle) 9 function shuffleArray(array) { 10 for (let i = array.length - 1; i > 0; i--) { 11 const j = Math.floor(Math.random() * (i + 1)); 12 [array[i], array[j]] = [array[j], array[i]]; 13 } 14 } 15 16 // Khóa lượt chÆ¡i: trang /game/<slug>/ tá»± ghi thá»ng kê theo slug trên URL, 17 // nên thẻ game phải tra Äúng slug Äó ("key" trong JSON Äôi khi khác slug). 18 // Link trá» thẳng folder game thô (vd "b/bankrobbery3") vẫn dùng key như cÅ©. 19 function playKey(g) { 20 var l = g && g.link ? String(g.link) : ""; 21 return l.indexOf("game/") === 0 ? l.slice(5).replace(/\/+$/, "") : (g ? g.key : ""); 22 } 23 24 // Function Äá» hiá»n thá» dữ liá»u 25 function displayValues(startIndex, endIndex) { 26 for (var i = startIndex; i < endIndex && i < jsonData.length; i++) { 27 item += ` 28 <div class="element-item"> 29 <div class="explore-wrapper"> 30 <div class="trending-items_wrapper"> 31 <div class="thumbnail"> 32 <a href="https://funny-school.github.io/${jsonData[i].link}/" data-game-key="${playKey(jsonData[i])}"> 33 <img src="${jsonData[i].image}" alt="${jsonData[i].title}" loading="lazy" decoding="async"> 34 </a> 35 </div> 36 <div class="product-discription"> 37 <div class="product-left"> 38 <a href="https://funny-school.github.io/${jsonData[i].link}/" data-game-key="${playKey(jsonData[i])}"> 39 <h5 class="title" style="font-size: 24px;"> 40 ${jsonData[i].title} 41 </h5> 42 </a> 43 <span class="fs-plays" data-playcount="${playKey(jsonData[i])}"></span> 44 </div> 45 </div> 46 </div> 47 </div> 48 </div>`; 49 } 50 $("#listgamespopular").html(item); 51 } 52 53 // Sá» game tá»i Äa hiá»n thá» á» mục Popular 54 var MAX_POPULAR = 200; 55 56 // Xếp hạng: game có lượt chÆ¡i lên trưá»c (nhiá»u -> Ãt); những game 57 // chưa có lượt nà o (data Firebase còn trá»ng) giữ thứ tá»± ngẫu nhiên. 58 // Khi Firebase chưa có dữ liá»u -> toà n bá» là 0 -> danh sách vẫn random 59 // y như cÅ©, và tá»± chuyá»n sang "theo Äá» phá» biến" khi lượt chÆ¡i tÃch lÅ©y. 60 function rankByPlays(data, counts) { 61 counts = counts || {}; 62 63 // loại trùng key (phòng data lặp) 64 var seen = {}; 65 data = data.filter(function(g) { 66 if (!g || !g.key || seen[g.key]) return false; 67 seen[g.key] = 1; 68 return true; 69 }); 70 71 shuffleArray(data); // tie-break ngẫu nhiên 72 data.sort(function(a, b) { 73 return (Number(counts[playKey(b)]) || 0) - (Number(counts[playKey(a)]) || 0); 74 }); 75 return data.slice(0, MAX_POPULAR); 76 } 77 78 // Xếp hạng trên TOÃN Bá» catalog (461 game), không chá» danh sách tuyá»n. 79 var popularReq = fetch('https://funny-school.github.io/assets/json/allGames.json') 80 .then(function(r) { return r.json(); }); 81 var countsReq = window.FSPlayCounts || Promise.resolve({}); 82 83 Promise.all([popularReq, countsReq]) 84 .then(function(res) { 85 jsonData = rankByPlays(res[0] || [], res[1]); 86 dataLength = jsonData.length; 87 displayValues(currentIndex, currentIndex + itemsPerPage); 88 currentIndex += itemsPerPage; 89 dataLength -= itemsPerPage; 90 }) 91 .catch(function(err) { 92 console.error('Error loading Popular list:', err); 93 }); 94 95 // Nút Load More click event 96 $('#loadMore').click(function() { 97 if (dataLength <= 0) { 98 $("#loadMore").prop('disabled', true).removeClass('btn-secondary'); 99 return; 100 } 101 102 displayValues(currentIndex, currentIndex + itemsPerPage); 103 currentIndex += itemsPerPage; 104 dataLength -= itemsPerPage; 105 106 if (dataLength <= 0) { 107 $("#loadMore").prop('disabled', true).removeClass('btn-secondary'); 108 } 109 }); 110});
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.