Skip to content

Commit a811ae5

Browse files
committed
tiki - wip
1 parent 1a82b93 commit a811ae5

File tree

5 files changed

+84
-140
lines changed

5 files changed

+84
-140
lines changed

popup/tabs.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ const tabs = [
175175
},
176176
{
177177
...CATEGORY.shopping,
178-
scripts: [s.shopee_topVariation, s.shopee_totalSpendMoney],
178+
scripts: [
179+
s.shopee_topVariation,
180+
s.shopee_totalSpendMoney,
181+
s.tiki_totalSpendMoney,
182+
],
179183
},
180184
{
181185
...CATEGORY.github,

scripts/backup/shopee-total-spend-money.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

scripts/backup/tiki-total-spend-money.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

scripts/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ import fb_openAdsActivities from "./fb_openAdsActivities.js";
153153
import fb_exportSaved from "./fb_exportSaved.js";
154154
import studyphim_unlimited from "./studyphim_unlimited.js";
155155
import shopee_totalSpendMoney from "./shopee_totalSpendMoney.js";
156+
import tiki_totalSpendMoney from "./tiki_totalSpendMoney.js";
156157

157158
// inject badges
158159
const allScripts = {
@@ -327,6 +328,7 @@ const allScripts = {
327328
fb_exportSaved: addBadge(fb_exportSaved, BADGES.new),
328329
studyphim_unlimited: addBadge(studyphim_unlimited, BADGES.new),
329330
shopee_totalSpendMoney: addBadge(shopee_totalSpendMoney, BADGES.new),
331+
tiki_totalSpendMoney: addBadge(tiki_totalSpendMoney, BADGES.beta),
330332
};
331333

332334
// alert(Object.keys(allScripts).length);

scripts/tiki_totalSpendMoney.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { showLoading } from "./helpers/utils.js";
2+
3+
export default {
4+
icon: "https://tiki.vn/favicon.ico",
5+
name: {
6+
en: "Tiki - Total spend money?",
7+
vi: "Tiki - Đã mua bao nhiêu tiền?",
8+
},
9+
description: {
10+
en: "See how much money you have spend on Tiki",
11+
vi: "Xem bạn đã mua hết bao nhiêu tiền trên Tiki",
12+
},
13+
14+
onClick: async () => {
15+
// https://tiki.vn/api/v2/orders?page=0&limit=10
16+
// https://www.facebook.com/groups/j2team.community/permalink/1169967376668714/
17+
18+
var totalOrders = 0;
19+
var totalSpent = 0;
20+
var pulling = true;
21+
var page = 1;
22+
23+
function getStatistics() {
24+
var orders = [];
25+
var xhttp = new XMLHttpRequest();
26+
xhttp.onreadystatechange = function () {
27+
if (this.readyState == 4 && this.status == 200) {
28+
orders = JSON.parse(this.responseText)["data"];
29+
pulling = orders.length >= 10;
30+
orders = orders.filter((order) => order["status"] == "hoan_thanh");
31+
totalOrders += orders.length;
32+
orders.forEach((order) => {
33+
let tpa = order["grand_total"];
34+
totalSpent += tpa;
35+
});
36+
page += 1;
37+
console.log("Đã lấy được: " + totalOrders + " đơn hàng");
38+
if (pulling) {
39+
console.log("Đang kéo thêm...");
40+
getStatistics();
41+
} else {
42+
console.log(
43+
"%cTổng đơn hàng đã giao: " + "%c" + moneyFormat(totalOrders),
44+
"font-size: 30px;",
45+
"font-size: 30px; color:red"
46+
);
47+
console.log(
48+
"%cTổng chi tiêu: " + "%c" + moneyFormat(totalSpent) + "đ",
49+
"font-size: 30px;",
50+
"font-size: 30px; color:red"
51+
);
52+
}
53+
}
54+
};
55+
xhttp.open(
56+
"GET",
57+
"https://tiki.vn/api/v2/me/orders?page=" + page + "&limit=10",
58+
true
59+
);
60+
xhttp.send();
61+
}
62+
63+
function moneyFormat(number, fixed = 0) {
64+
if (isNaN(number)) return 0;
65+
number = number.toFixed(fixed);
66+
let delimeter = ",";
67+
number += "";
68+
let rgx = /(\d+)(\d{3})/;
69+
while (rgx.test(number)) {
70+
number = number.replace(rgx, "$1" + delimeter + "$2");
71+
}
72+
return number;
73+
}
74+
75+
getStatistics();
76+
},
77+
};

0 commit comments

Comments
 (0)