PageSourceSearch

https://funny-school.github.io/assets/js/getlistdatapopular.js

js funny-school.github.io collected 2026-10-03 09:13:34 UTC 4,581 bytes, 110 lines download raw bytes

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.