|
const clickDelta = 4000; // ms delay between clicks |
|
const cycleDelta = clickDelta * 100; // ms delay between share cycles |
|
|
|
const clickLinks = (el) => { |
|
el.click(); |
|
|
|
// set a short timeout so there's time to load in the active parties/render the modal |
|
setTimeout(() => { |
|
document |
|
.querySelectorAll("[data-et-name='share_poshmark']") |
|
.forEach((el) => el.click()); |
|
}, 200); |
|
}; |
|
|
|
const notSold = (el) => { |
|
return ( |
|
el |
|
.closest(".card") |
|
.querySelectorAll(".sold-tag,.sold-out-tag,.not-for-sale-tag") |
|
.length === 0 |
|
); |
|
}; |
|
|
|
// check if there are any sold tags on page |
|
const hasSold = () => document.querySelectorAll(".sold-tag,.sold-out-tag").length > 0 |
|
|
|
// one screen height from the bottom |
|
const nearBottom = () => document.body.scrollHeight - window.innerHeight; |
|
|
|
const scrollToBottomAndWait = () => { |
|
if (!hasSold()) { |
|
window.scrollTo(0, nearBottom()); |
|
} |
|
|
|
return new Promise((resolve) => { |
|
setTimeout(() => { |
|
const isScrolledToBottom = |
|
window.innerHeight + window.scrollY >= nearBottom(); |
|
if (!isScrolledToBottom && !hasSold()) { |
|
resolve(scrollToBottomAndWait()); |
|
} else { |
|
resolve(); |
|
} |
|
}, 2000); |
|
}); |
|
}; |
|
|
|
const share = async () => { |
|
await scrollToBottomAndWait(); |
|
|
|
let timeout = 0; |
|
const doShare = (el) => { |
|
if (notSold(el)) { |
|
// register link clicking |
|
setTimeout(() => clickLinks(el), timeout); |
|
|
|
// make sure next registered click comes after |
|
timeout += clickDelta; |
|
} |
|
}; |
|
|
|
const shareLinks = Array.from(document.querySelectorAll("[data-et-name=share]")).reverse(); |
|
shareLinks.forEach(doShare); |
|
}; |
|
|
|
share(); |
|
setInterval(share, cycleDelta); |
@SeanMcGrath Thanks for sharing this code! I have a question about the last 2 lines:
I'm presuming that cycleDelta get incremented after it's first declared, so that it adds up to the total amount of time it takes to get through one cycle. But I don't understand how. Can you explain? (I'm new to JavaScript, so apologies if this is a silly question.)