Skip to content

Instantly share code, notes, and snippets.

@SeanMcGrath
Last active October 14, 2024 01:41
Show Gist options
  • Save SeanMcGrath/fb4f9e1869a2252738c9398d5ceb5395 to your computer and use it in GitHub Desktop.
Save SeanMcGrath/fb4f9e1869a2252738c9398d5ceb5395 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
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);
@anonymousng
Copy link

anonymousng commented Jul 28, 2020 via email

@visceraeyes
Copy link

nice find that old one works!

@TrentStephens
Copy link

Can anyone share the old code with me too? I can't quite figure out what the right one is based on the revisions.

@visceraeyes
Copy link

var clickDelta = 2000; // ms delay between clicks
var cycleDelta = clickDelta * 100; // ms delay between share cycles

// do the actual clicking
var clickLinks = function() {
$(this).click();
$("[data-pa-name^='share_poshmark']").click();
};

var notSold = function(el) {
return $(el).closest('.tile').find('.sold-tag,.sold-out-tag,.not-for-sale-tag').length === 0;
};

function share() {
var timeout = 0;
var doShare = function() {
if (notSold(this)) {
// register link clicking
setTimeout(clickLinks.bind(this), timeout);

                // make sure next registered click comes after
                timeout += clickDelta;
    	}
};

// for each share link
$($('a.share').get().reverse()).each(doShare);

};

share();
setInterval(share, cycleDelta);

@yada-yoda
Copy link

Has anyone had any luck on either script? Seems the old nor the new one have been working for me.

@SeanMcGrath
Copy link
Author

I haven't had a lot of time to dig into it, but last I checked poshmark had changed their UI in such a way that this kind of approach is now much more difficult, maybe impossible. Would love to be proved wrong though

@anonymousng
Copy link

anonymousng commented Sep 9, 2020 via email

@yada-yoda
Copy link

New script is working for me.

On Wed, Sep 9, 2020 at 7:32 PM yada-yoda @.> wrote: @.* commented on this gist. ------------------------------ Has anyone had any luck on either script? Seems the old nor the new one have been working for me. — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://gist.github.com/fb4f9e1869a2252738c9398d5ceb5395#gistcomment-3447434, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANQCDM643TGRVHX2OX4CCULSE6DJFANCNFSM4I3QBTDQ .
-- HAVE A NICE DAY......

Are you using it in a Chrome Snippet in the Developer panel or as a JS Bookmarklet? Seems none of them are working for me from my closet

@yada-yoda
Copy link

Also this is the error in the console I receive when trying to run the latest, if it helps at all:

VM505:1 Uncaught SyntaxError: Identifier 'poshmark_share_closet' has already been declared

@jackjj22
Copy link

jackjj22 commented Sep 11, 2020

The new script is working perfectly for me in the firefox developer console.

@SeanMcGrath
Copy link
Author

i suspect it's working for some people and not others due to experimental features poshmark is showing to some % of users. It's normal for sites like this to A/B test different UIs, and there seems to be at least one variant where this doesn't work

@anonymousng
Copy link

anonymousng commented Sep 11, 2020 via email

@anonymousng
Copy link

anonymousng commented Oct 8, 2020 via email

@suezhuny
Copy link

suezhuny commented Dec 4, 2020

This is such elegant and beautiful and clean code, I have no javascript background but your notes are so clear and code easy to follow!!! Kudos!!!

@suezhuny
Copy link

Hi, after many days of success, it has stopped working, I can see the page is still sharing, but I do not get the shared successfully notification. Any ideas how to fix it? Thank you!

@creationmbt
Copy link

This code seems to be working which is awesome, but can anyone provide a code that shares the items in reverse? ( from the end of the closet to the top) This will ensure the whole closet gets share, otherwise when the captcha comes up it starts sharing from the top again and only a portion of the closet gets share in a loop. If no captcha comes up the entire closet gets share which is great but often times the captcha pops up more than once in a short amount of time, thus the same items keep re-sharing and a portion don't get shared. Sorry for the ramble, I have no background in coding at all and I'm just learning as I go. Thanks in advance :)

@SAUL700620
Copy link

Sean :

The code runs just fine, however I don't know in which order is sharing the items, so as a computer programmer I am trying to understand the code ( I am java programmer, not javascript) and I found thing that I really don't understand, if you could elaborate a little bit in regard where they come from or how did you came up with them, for example :
1. - const clickLinks = (el) => {
el.click(); The variable "el" where does it come from, where it was declared ?

2.-   "[data-et-name^='share_poshmark']"       How did you come up with this string  ? or
       '.sold-tag,.sold-out-tag,.not-for-sale-tag'  the same for these tags,  where did you get them, if could eleborate by explaining more or which tool you used to know all this, it would be a great help.

Thanks in advance

@SeanMcGrath
Copy link
Author

clickLinks is a function defined using ES6 arrow notation. el is the function's single argument.

The strings you are referring to are known as CSS selectors. I constructed them by inspecting the Poshmark DOM and figuring out what attributes were used to identify valid share buttons.

@svetlanasdsf
Copy link

Seems like this is broken, as of today. Tried on several browsers/machines with the same result, the action isn't getting triggered. Is anyone else noticing this?

@blublulady
Copy link

Yes, stopped working yesterday :(

@visceraeyes
Copy link

This script had a great run,i appreciate you helping with my sales.

@SeanMcGrath
Copy link
Author

fixed, poshmark renamed the "tile" class to "card" and the script had to be updated to reflect this.

@blublulady
Copy link

You rock! Thank you so much!

@svetlanasdsf
Copy link

svetlanasdsf commented Mar 21, 2022 via email

@Almozza
Copy link

Almozza commented May 11, 2023

thank you worked perfectly well! any other codes to share other sellers listings and follow?)))

@ianmcilwraith
Copy link

I forked this gist here to accommodate larger closets with 40+ items for anyone with that need!
https://gist.github.com/ianmcilwraith/30dbeb61edda08c2be039818067a1781

@biancawriter
Copy link

@SeanMcGrath Thanks for sharing this code! I have a question about the last 2 lines:

 share();
 setInterval(share, cycleDelta);

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.)

@SeanMcGrath
Copy link
Author

cycleDelta is the interval between runs of the share function. the value of cycleDelta itself is constant. setInterval(x, y) runs the specified function x every y milliseconds.

@SeanMcGrath
Copy link
Author

updated to incorporate @ianmcilwraith 's changes (thanks!) and also stop scrolling down the page once sold items are found.

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