Type something and hit enter

ads here
On
advertise here

I'm an extremely lazy guy when it comes to menial repetitive tasks. I hate going to my grocer's website to load my card with coupons. I'm not sure where you shop, but I specifically use Crogür, very nearby the state of Stagrâm. I will include an explanation so that you can do this for a competitor as well, as you might not shop at Crogür. Oh, and, if you're diligent about coupon clipping, this isn't for you. This is for people that hate repetitive work.

Let's say the Crogür website allows you to clip up to 150 coupons. They have way more than that. I don't have time to sort through all the crap. I'd rather just load the first 150 coupons into my card and then hope that I end up buying one of the things I clipped. The coupons get auto-applied whenever you use your Crogür card, so chances are you'll end up saving money at some point. I mean, you're clipping 150 coupons. You're going to end up buying something that's on sale.

First, an explanation.

Here's the code you're going to be executing and an explanation.

var buttons = document.getElementsByClassName('CouponButton'); var i = 0; numberOfButtons = buttons.length; function pressButton() { buttons[i].click(); i++; if( i < numberOfButtons ){ setTimeout( pressButton, 500 ); } } pressButton(); 

First, you're telling your browser to find all the elements with a particular class. A class is a non-unique label that you can give to an HTML element that describes it. On a page with 100 buttons that all say "add coupon," they're all probably going to have the same classes. If so, we can use that to identify all the "add coupon" buttons.

In this case, using Chrome (or whatever browser, I guess), we right click one of the buttons and select "Inspect this element." We then find the classes to the "button" element of the thing we're inspecting (if the inspector took you to a lower level of that button, just look a bit higher for the button). In this case, I chose to use the class "CouponButton." So the code is grabbing all the elements with that class and putting them in an array (think of it as a bag or box).

Now that I've got all those juicy coupon buttons in a bag, I'm going to start a repetitive loop. I'm telling the browser, OK, you're going to do this (click it) once for every single stupid button in this bag. HOWEVER, I set a timeout of 500 milliseconds. I found that if you do not set this timeout, it will add 150 coupons in one second. The website will become very upset at you and kick you out and not let you back in until you clear your cookies. If you want to play around with making the script faster or slower, then edit the "500" value.

Now that you understand the code, you go to this link to create a bookmark with the code so that you can run it easily. This is what we get:

javascript:(function()%7Bvar buttons %3D document.getElementsByClassName('CouponButton')%3Bvar i %3D 0%3BnumberOfButtons %3D buttons.length%3Bfunction pressButton() %7Bbuttons%5Bi%5D.click()%3Bi%2B%2B%3Bif( i < numberOfButtons )%7BsetTimeout( pressButton%2C 500 )%3B%7D%7DpressButton()%7D)() 

Add a new bookmark with the above set as the URL.

Visit the Crogür website. Login to your account. Go to the page with all the coupon buttons. Press your bookmark once. The buttons will start autoclicking, one per 500 milliseconds.

Note, it will find more than 150 buttons, so it will keep clicking. You can refresh the page to stop the script at this point. Maybe a smarter person than myself can add a smarter way to do this so that it doesn't just do it 150 times period.

Anyway, I hope you learned something and I hope this saves you some money.



January 27, 2019 at 11:01AM

Click to comment