Skip to content

Instantly share code, notes, and snippets.

@heypoom
Last active July 9, 2024 15:19
Show Gist options
  • Select an option

  • Save heypoom/33d3578ceeabb15a3040fd9079564f37 to your computer and use it in GitHub Desktop.

Select an option

Save heypoom/33d3578ceeabb15a3040fd9079564f37 to your computer and use it in GitHub Desktop.
// First, go to https://shopee.co.th/user/purchase, and open DevTools.
// Step 1 - Run this code to scroll all the way to the bottom.
const timer = setInterval(() => scrollTo(0, 10000000), 800)
setTimeout(() => {
// Step 2 - Stop scrolling after 1 minute.
clearInterval(timer)
// Step 3 - Sum the total purchase price!
const total = [...document.querySelectorAll('.purchase-card-buttons__total-price')]
.map(n => parseInt(n.innerText.slice(1).replace(/,/g, '')))
.reduce((a, b) => a + b)
console.log('Total =', total)
}, 60 * 1000)
@astider

astider commented Jan 3, 2021

Copy link
Copy Markdown

[...document.querySelectorAll('.purchase-card-buttons__total-price')].map(n => parseInt(n.innerText.slice(1).replaceAll(',',''))).reduce((a, b) => a + b)

quick fix

@heypoom

heypoom commented Jan 3, 2021

Copy link
Copy Markdown
Author

เพิ่งรู้ว่ามี replaceAll! ขอบคุณฮะ

ปกติใช้ .replace(/,/g, '') เอา

@jukbot

jukbot commented Jan 3, 2021

Copy link
Copy Markdown

Filter เฉพาะรายการที่ชำระสำเร็จ https://shopee.co.th/user/purchase?type=3

ไม่งั้นต้อง filter เอาแบบนี้ 😂

[...document.querySelectorAll('.purchase-list-page__checkout-card-wrapper')]
.filter((parent) => parent.innerHTML.includes('ดูข้อมูลการสั่งซื้อ'))
.map((parent) => parseInt(parent.querySelector('.purchase-card-buttons__total-price').innerText.slice(1).replaceAll(',','')))
.reduce((a, b) => a + b)

@ntsd

ntsd commented Jan 3, 2021

Copy link
Copy Markdown

Add more statistic calculation

mean, median, max, min

function median(numbers) {
    const sorted = numbers.slice().sort((a, b) => a - b);
    const middle = Math.floor(sorted.length / 2);

    if (sorted.length % 2 === 0) {
        return (sorted[middle - 1] + sorted[middle]) / 2;
    }

    return sorted[middle];
}

// Step 1 - Run this code to scroll all the way to the bottom.
const timer = setInterval(() => scrollTo(0, 10000000), 800)

setTimeout(() => {
  // Step 2 - Stop scrolling after 1 minute.
  clearInterval(timer)

  const priceList =  [...document.querySelectorAll('.purchase-card-buttons__total-price')]
    .map(n => parseInt(n.innerText.slice(1).replace(/,/g, '')));
  // Step 3 - Sum the total purchase price!
  const total = priceList.reduce((a, b) => a + b);
  const mean = total / priceList.length;
  console.log("Total =", total);
  console.log("Mean =", mean);
  console.log("Median =", median(priceList))
  console.log("Max =", Math.max(...priceList));
  console.log("Min =", Math.min(...priceList));
}, 30000)

@PaperMonster

PaperMonster commented Jan 4, 2021

Copy link
Copy Markdown

My colleague hit time limit and still had more to scroll. So here is auto scrolling without time limit and number of purchases added.

function median(numbers) {
    const sorted = numbers.slice().sort((a, b) => a - b);
    const middle = Math.floor(sorted.length / 2);

    if (sorted.length % 2 === 0) {
        return (sorted[middle - 1] + sorted[middle]) / 2;
    }

    return sorted[middle];
}

// Step 1 - Keep scrolling until scroll position has stopped increasing for 5 intervals
const scrollHistory = [];
const historySize = 5;  // Increase this if autoscroll ends too soon
const timer = setInterval(() => {
    scrollTo(0, document.body.scrollHeight);
    if(scrollHistory.length === historySize && scrollHistory.every(val => val === scrollHistory[0])) {
        clearInterval(timer);
        // Step 2 - Sum the total purchase price!
        const priceList =  [...document.querySelectorAll('.purchase-card-buttons__total-price')]
                    .map(n => parseInt(n.innerText.slice(1).replace(/,/g, '')));
        const total = priceList.reduce((a, b) => a + b);
        const mean = total / priceList.length;
        console.log("Total =", total);
        console.log("Mean =", mean);
        console.log("Median =", median(priceList))
        console.log("Max =", Math.max(...priceList));
        console.log("Min =", Math.min(...priceList));
        console.log("Number of purchases =", priceList.length);
    } else {
        if(scrollHistory.length === historySize) scrollHistory.shift();
        scrollHistory.push(window.scrollY)
        console.log('Looking through your orders, please do not touch anything and wait...');
    }
}, 800)

@wit03

wit03 commented Jul 6, 2021

Copy link
Copy Markdown

Right now the element's classname is changed to "isoXOF"

function median(numbers) {
    const sorted = numbers.slice().sort((a, b) => a - b);
    const middle = Math.floor(sorted.length / 2);

    if (sorted.length % 2 === 0) {
        return (sorted[middle - 1] + sorted[middle]) / 2;
    }

    return sorted[middle];
}

// Step 1 - Keep scrolling until scroll position has stopped increasing for 5 intervals
const scrollHistory = [];
const historySize = 5;  // Increase this if autoscroll ends too soon
const timer = setInterval(() => {
    scrollTo(0, document.body.scrollHeight);
    if(scrollHistory.length === historySize && scrollHistory.every(val => val === scrollHistory[0])) {
        clearInterval(timer);
        // Step 2 - Sum the total purchase price!
        const priceList =  [...document.querySelectorAll('.isoXOF')]
                    .map(n => parseInt(n.innerText.slice(1).replace(/,/g, '')));
        const total = priceList.reduce((a, b) => a + b);
        const mean = total / priceList.length;
        console.log("Total =", total);
        console.log("Mean =", mean);
        console.log("Median =", median(priceList))
        console.log("Max =", Math.max(...priceList));
        console.log("Min =", Math.min(...priceList));
        console.log("Number of purchases =", priceList.length);
    } else {
        if(scrollHistory.length === historySize) scrollHistory.shift();
        scrollHistory.push(window.scrollY)
        console.log('Looking through your orders, please do not touch anything and wait...');
    }
}, 800)

@jukbot

jukbot commented Aug 16, 2021

Copy link
Copy Markdown

กลับมาดู script shopee ควรทำ BI analytics การซื้อของแต่ละคน 😂

@chino-pack

Copy link
Copy Markdown

ไม่ทราบว่าตอนนี้ element's classname ถูกเปลี่ยนอีกแล้วหรอครับ ใช้โค้ดข้างบนแล้วรันไม่ได้

@wit03

wit03 commented Sep 25, 2021

Copy link
Copy Markdown

@PackChinoros ใช่ครับ ตอนนี้เปลี่ยนจาก ".isoXOF" เป็น "._1MS3t2" ได้เลยครับ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment