Skip to content

Instantly share code, notes, and snippets.

@ianmcilwraith
Forked from SeanMcGrath/poshmark-share
Last active April 6, 2024 06:59
Show Gist options
  • Save ianmcilwraith/30dbeb61edda08c2be039818067a1781 to your computer and use it in GitHub Desktop.
Save ianmcilwraith/30dbeb61edda08c2be039818067a1781 to your computer and use it in GitHub Desktop.
JS code to share all items in a poshmark closet to followers and all available events
// Share your poshmark closet on a loop.
// only likely to work in modern browers, Chrome preferred but works in Safari.
// Paste this into the console or make a javascript bookmarklet
// This fork is designed to work on large closets with 40+ items
const clickDelta = 2000; // 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
);
};
const scrollToBottomAndWait = () => {
window.scrollTo(0, document.body.scrollHeight);
return new Promise((resolve) => {
setTimeout(() => {
const isScrolledToBottom =
window.innerHeight + window.scrollY >= document.body.scrollHeight;
if (!isScrolledToBottom) {
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment