Last active
December 26, 2024 22:05
-
-
Save SamadiPour/a18b1e186deac76c4a95fa108d02a6ea to your computer and use it in GitHub Desktop.
Snappfood Spent money
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cookies = Object.fromEntries(document.cookie.split('; ').map(c => c.split('='))); | |
let UDID = cookies.UDID; | |
let jwt = cookies[['jwt-access_token']] ?? JSON.parse(window.localStorage.JWT ?? '{}').access_token; | |
var myHeaders = new Headers(); | |
myHeaders.append("authority", "snappfood.ir"); | |
myHeaders.append("accept", "application/json, text/plain, */*"); | |
myHeaders.append("accept-language", "en-US,en;q=0.9,fa;q=0.8"); | |
myHeaders.append("authorization", "Bearer " + jwt); | |
myHeaders.append("content-type", "application/x-www-form-urlencoded"); | |
myHeaders.append("referer", "https://snappfood.ir/profile/orders"); | |
myHeaders.append("sec-ch-ua", "\".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\""); | |
myHeaders.append("sec-ch-ua-mobile", "?1"); | |
myHeaders.append("sec-ch-ua-platform", "\"Android\""); | |
myHeaders.append("sec-fetch-dest", "empty"); | |
myHeaders.append("sec-fetch-mode", "cors"); | |
myHeaders.append("sec-fetch-site", "same-origin"); | |
myHeaders.append("user-agent", "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Mobile Safari/537.36"); | |
const requestOptions = { | |
method: 'GET', | |
headers: myHeaders, | |
redirect: 'follow' | |
}; | |
let pageSize = 1000; | |
let pageNumber = 0; | |
let allOrders = []; | |
let count = 1; | |
while (pageNumber * pageSize < count) { | |
console.log(`Getting ${pageNumber * pageSize} - ${(pageNumber + 1) * pageSize}...`); | |
let response = await fetch(`https://snappfood.ir/mobile/v1/order/reorder?optionalClient=WEBSITE&client=WEBSITE&deviceType=WEBSITE&appVersion=8.1.1&UDID=${UDID}&page=${pageNumber}&size=${pageSize}&locale=fa`, requestOptions); | |
const responseData = await response.json(); | |
const orders = responseData.data.orders; | |
count = responseData.data.count ?? 0; | |
if (orders.length === 0) break; | |
allOrders = allOrders.concat(orders); | |
pageNumber++; | |
} | |
let price = 0; | |
let discount = 0; | |
for (let i = 0; i < allOrders.length; i++) { | |
let order = allOrders[i]; | |
if (!order.orderCanceled) { | |
price += order.totalPrice; | |
discount += order.sumAllDiscount; | |
} | |
} | |
const today = new Date(); | |
const oldestOrderDate = new Date(allOrders.at(-1).startedAt); | |
const timeDiff = today.getTime() - oldestOrderDate.getTime(); | |
const daysDiff = Math.floor(timeDiff / (1000 * 3600 * 24)); | |
const yearsDiff = Math.floor(daysDiff / 365); | |
const remainingDays = daysDiff % 365; | |
const conversionResponse = await fetch(`https://raw.githubusercontent.com/SamadiPour/rial-exchange-rates-archive/data/gregorian_imp.min.json`); | |
const conversionResponseData = await conversionResponse.json(); | |
const conversionRates = new Map( | |
Object.entries(conversionResponseData).map(([key, value]) => [key, value.usd.buy ?? value.usd.sell]) | |
); | |
const lastConversionRate = [...conversionRates.values()].at(-1) | |
let usd = 0; | |
for (let i = 0; i < allOrders.length; i++) { | |
let order = allOrders[i]; | |
if (!order.orderCanceled) { | |
let dateString = new Date(order.startedAt).toLocaleDateString('en-CA', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/-/g, '/'); | |
let usdRate = conversionRates.get(dateString) ?? lastConversionRate; | |
usd += order.totalPrice / usdRate; | |
} | |
} | |
console.log('%c---------------', 'color: #888; font-weight: bold;'); | |
console.log('%cTotal order:%c %s', 'color: #3498db; font-weight: bold;', 'color: #c0c0c0;', allOrders.length); | |
console.log('%cTotal spent:%c %s Toman', 'color: #3498db; font-weight: bold;', 'color: #e74c3c;', price.toLocaleString()); | |
console.log('%cTotal spent in USD:%c $%s', 'color: #3498db; font-weight: bold;', 'color: #e74c3c;', usd.toLocaleString()); | |
console.log('%cTotal discount:%c %s Toman', 'color: #3498db; font-weight: bold;', 'color: #2ecc71;', discount.toLocaleString()); | |
console.log('%cOldest order date:%c %s (%d years and %d days ago)', 'color: #3498db; font-weight: bold;', 'color: #f39c12;', oldestOrderDate.toLocaleDateString('en-CA'), yearsDiff, remainingDays); |
- تو مرورگر دسکتاپ اسنپ فود رو باز کنید (نسخه موبایلشو باز نکنید)
- اگر لاگین نیستید، لاگین کنید.
- بعد راست کلیک کنید و گزینه Inspect رو انتخاب کنید
- برید تب کنسول
- اسکریپت رو paste کنید
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For snapp.express use this snippet code: