├── calculate.js ├── calculate_ui.js ├── README.md └── calculate_with_csv.js /calculate.js: -------------------------------------------------------------------------------- 1 | var total = 0; 2 | var order = 0; 3 | function calculate(next){ 4 | var opts = { 5 | method: 'GET', 6 | headers: {} 7 | }; 8 | fetch('https://shopee.com.my/api/v4/order/get_order_list?limit=5&list_type=3&offset='+next, opts).then(function (response) { 9 | return response.json(); 10 | }) 11 | .then(function (body) { 12 | var next_offset = body.data.next_offset; 13 | if(next_offset >= 0){ 14 | for (let [key, value] of Object.entries(body.data.details_list)) { 15 | var total_temp = value.info_card.final_total / 100000; 16 | total += total_temp; 17 | order++; 18 | console.log(order + ":", "RM " + total_temp + " - ", value.info_card.order_list_cards[0].product_info.item_groups[0].items[0].name); 19 | } 20 | calculate(next_offset); 21 | } else { 22 | console.log('Calculation completed!'); 23 | console.log('GRAND TOTAL: RM ' + Math.round(total * 100) / 100); 24 | } 25 | }); 26 | } 27 | calculate(0); 28 | -------------------------------------------------------------------------------- /calculate_ui.js: -------------------------------------------------------------------------------- 1 | javascript:(function(){ 2 | 3 | var navbar = document.getElementsByClassName("navbar__links")[0]; 4 | var navbarLink = document.createElement("li"); 5 | navbar.appendChild(navbarLink); 6 | navbarLink.className = "navbar__link"; 7 | 8 | var total = 0; 9 | var order = 0; 10 | function calculate(next){ 11 | var opts = { 12 | method: 'GET', 13 | headers: {} 14 | }; 15 | fetch('https://shopee.com.my/api/v4/order/get_order_list?limit=5&list_type=3&offset='+next, opts).then(function (response) { 16 | return response.json(); 17 | }) 18 | .then(function (body) { 19 | var next_offset = body.data.next_offset; 20 | if(next_offset >= 0){ 21 | for (let [key, value] of Object.entries(body.data.details_list)) { 22 | var total_temp = value.info_card.final_total / 100000; 23 | total += total_temp; 24 | order++; 25 | console.log(order + ":", "RM " + total_temp + " - ", value.info_card.order_list_cards[0].product_info.item_groups[0].items[0].name); 26 | navbarLink.innerHTML="Calculating: RM " + Math.round(total * 100) / 100; 27 | 28 | } 29 | calculate(next_offset); 30 | } else { 31 | console.log('Calculation completed!'); 32 | var grandTotal = Math.round(total * 100) / 100; 33 | console.log('GRAND TOTAL: RM ' + grandTotal); 34 | 35 | navbarLink.innerHTML="Grand Total: RM " + grandTotal; 36 | } 37 | }); 38 | } 39 | calculate(0); 40 | 41 | })(); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## IMPORTANT UPDATE 2 | 3 | # This script is no longer work and not updated. Please use new Chrome Extension here https://github.com/epool86/shopee_order_history 4 | 5 | # calculateshopee 6 | 7 | Just open shopee web and login, then copy & paste this javascript, lastly simply run calculate(0); 8 | 9 | - Use calculate.js to calculate in console 10 | - Use calculate_with_csv.js to calculate in console & generate CSV 11 | - Use calculate_ui to display total directly on web page 12 | 13 | **Instructions** 14 | 15 | - Copy code from one of the file (calculate.js, calculate_with_csv, or calculate_ui) 16 | - Open Shopee's website and log in into your account 17 | - Open browser developer tool > console (rightt click > inspect > console tab) 18 | - Paste the code and press enter 19 | 20 | **Using Calculate Bookmarklet (optional)** 21 | 22 | - Go to https://caiorss.github.io/bookmarklet-maker/ 23 | - Copy & Paste "calculate_ui.js" into Code section > Fill the title with "Shopee Total" > Click "Generate Bookmarklet" > Drag Link under "Generate Bookmarklet" button to your bookmark bar. 24 | - Go to Shopee website. Click the bookmark "Shopee Total". Result will appear beside your Shopee username. 25 | 26 | NOTE 27 | 1. Only calculate order in "Completed" section 28 | 2. Doesn't count order in "To Ship", "To Receive" section 29 | 3. Only display 1st item (if more than 1 item in single order) but still count total value of order 30 | 31 | Credit (for CSV file generator) 32 | https://stackoverflow.com/a/24922761 33 | -------------------------------------------------------------------------------- /calculate_with_csv.js: -------------------------------------------------------------------------------- 1 | var total_spent = 0; 2 | var order_count = 0; 3 | var datacsv = []; 4 | function calculate(next){ 5 | var opts = { 6 | method: 'GET', 7 | headers: {} 8 | }; 9 | fetch('https://shopee.com.my/api/v4/order/get_order_list?limit=5&list_type=3&offset='+next, opts) 10 | .then(function (response) { 11 | return response.json(); 12 | }) 13 | .then(function (body) { 14 | var next_offset = body.data.next_offset; 15 | if(next_offset >= 0){ 16 | for (let [key, value] of Object.entries(body.data.details_list)) { 17 | var total_temp = value.info_card.final_total / 100000; 18 | total_spent += total_temp; 19 | datacsv[order_count] = [order_count + 1, total_temp, value.info_card.order_list_cards[0].product_info.item_groups[0].items[0].name]; 20 | order_count++; 21 | console.log(order_count + ":", "RM " + total_temp + " - ", value.info_card.order_list_cards[0].product_info.item_groups[0].items[0].name); 22 | } 23 | calculate(next_offset); 24 | } else { 25 | exportToCsv('export.csv', datacsv); 26 | console.log('Calculation completed!'); 27 | console.log('GRAND TOTAL: RM ' + Math.round(total_spent * 100) / 100 ); 28 | } 29 | }); 30 | } 31 | //credit to https://stackoverflow.com/a/24922761 32 | function exportToCsv(filename, rows) { 33 | var processRow = function (row) { 34 | var finalVal = ''; 35 | for (var j = 0; j < row.length; j++) { 36 | var innerValue = row[j] === null ? '' : row[j].toString(); 37 | if (row[j] instanceof Date) { 38 | innerValue = row[j].toLocaleString(); 39 | }; 40 | var result = innerValue.replace(/"/g, '""'); 41 | if (result.search(/("|,|\n)/g) >= 0) 42 | result = '"' + result + '"'; 43 | if (j > 0) 44 | finalVal += ','; 45 | finalVal += result; 46 | } 47 | return finalVal + '\n'; 48 | }; 49 | var csvFile = ''; 50 | for (var i = 0; i < rows.length; i++) { 51 | csvFile += processRow(rows[i]); 52 | } 53 | var blob = new Blob([csvFile], { type: 'text/csv;charset=utf-8;' }); 54 | if (navigator.msSaveBlob) { // IE 10+ 55 | navigator.msSaveBlob(blob, filename); 56 | } else { 57 | var link = document.createElement("a"); 58 | if (link.download !== undefined) { // feature detection 59 | // Browsers that support HTML5 download attribute 60 | var url = URL.createObjectURL(blob); 61 | link.setAttribute("href", url); 62 | link.setAttribute("download", filename); 63 | link.style.visibility = 'hidden'; 64 | document.body.appendChild(link); 65 | link.click(); 66 | document.body.removeChild(link); 67 | } 68 | } 69 | } 70 | calculate(0); 71 | --------------------------------------------------------------------------------