Bao năm qua bạn đã "cống nạp" bao nhiêu tiền cho Shopee? Khám phá ngay!
LƯU Ý BẢO MẬT & AN TOÀN
Đoạn mã (script) dưới đây được thực thi an toàn ngay trên trình duyệt (tab) của bạn. Tool hoàn toàn không yêu cầu nhập mật khẩu hay gửi dữ liệu của bạn đến bất kỳ máy chủ nào khác. Nó chỉ tính toán và hiển thị cho riêng bạn xem.
✍️ Hướng dẫn các bước thực hiện:
Mở một tab mới và truy cập, đăng nhập vào trang shopee.vn.
Sau khi trang Shopee đã load xong, hãy nhấn phím F12 (trên Windows) hoặc Cmd + Option + I (trên Mac), hoặc click chuột phải chọn Kiểm tra (Inspect).
Chuyển sang tab Console trong cửa sổ DevTools vừa hiện ra.
Bấm nút "Copy mã" bên dưới, dán toàn bộ mã vào tab Console đó và nhấn Enter.
Ngồi nhâm nhi tách trà và chờ đoạn mã quét lịch sử đơn hàng của bạn. Khi xong, hệ thống sẽ tự động tổng hợp và hiện thông báo kết quả.
💻 Đoạn mã JavaScript:
script.js
async function calculateShopeeSpending() {
console.log("%c🚀 Đang bắt đầu tính toán chi tiêu...", "color: #ee4d2d; font-size: 16px; font-weight: bold;");
let totalSpent = 0;
let totalOrders = 0;
let totalItems = 0;
let nextOffset = ""; // Dùng next_offset của API thay vì cộng cứng 20
const limit = 20;
let hasMore = true;
let pageCount = 1;
while (hasMore) {
try {
console.log(`Đang tải dữ liệu trang ${pageCount}... xin đợi...`);
// Thống nhất dùng get_all_order_and_checkout_list để lấy được tất cả
const url = `https://shopee.vn/api/v4/order/get_all_order_and_checkout_list?limit=${limit}&offset=${nextOffset}`;
const response = await fetch(url);
const data = await response.json();
let orders = [];
let newNextOffset = "";
if (data && data.new_data && data.new_data.order_or_checkout_data) {
orders = data.new_data.order_or_checkout_data;
newNextOffset = data.new_data.next_offset;
} else if (data && data.data && data.data.details_list) {
orders = data.data.details_list;
newNextOffset = data.data.next_offset;
}
if (!orders || orders.length === 0) {
hasMore = false;
break;
}
for (let order of orders) {
let infoCard = null;
let listType = null;
if (order.order_list_detail && order.order_list_detail.info_card) {
infoCard = order.order_list_detail.info_card;
listType = order.order_list_detail.list_type;
} else if (order.info_card) {
infoCard = order.info_card;
listType = order.info_card.list_type || (order.status && order.status.status_label.text === 'label_order_completed' ? 3 : 0);
}
// Chỉ tính đơn hàng Thành công (list_type = 3)
if (infoCard && listType === 3) {
const amountStr = infoCard.final_total / 100000;
totalSpent += amountStr;
totalOrders++;
// Đoán số lượng sản phẩm (hoặc lấy product_count nếu có)
if (infoCard.product_count) {
totalItems += infoCard.product_count;
} else if (infoCard.order_list_cards && infoCard.order_list_cards[0].items) {
totalItems += infoCard.order_list_cards[0].items.length;
}
}
}
// Cập nhật offset mới
if (!newNextOffset) {
hasMore = false;
} else {
nextOffset = newNextOffset;
pageCount++;
}
// Delay 1 giây để tránh bị block do rate limit
await new Promise(r => setTimeout(r, 1000));
} catch (error) {
console.error("Lỗi khi tải dữ liệu:", error);
hasMore = false;
}
}
const formatter = new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' });
const amountFormatted = formatter.format(totalSpent);
console.log("%c=================================", "color: #4CAF50");
console.log("%c🎉 TÍNH TOÁN HOÀN THÀNH!", "color: #4CAF50; font-size: 20px; font-weight: bold;");
console.log(`📦 Tổng số đơn hàng: ${totalOrders} đơn`);
console.log(`🛍️ Số lượng sản phẩm: ${totalItems} món`);
console.log(`%c💰 TỔNG CHI TIÊU: ${amountFormatted}`, "color: #ee4d2d; font-size: 18px; font-weight: bold;");
console.log("%c=================================", "color: #4CAF50");
alert(`Báo cáo chi tiêu Shopee:\n- Tổng số đơn hàng: ${totalOrders} đơn\n- Tổng chi tiêu: ${amountFormatted}\n\nXem chi tiết tại tab Console!`);
}
calculateShopeeSpending();