So I’m trying to auto-click every button in Instagram’s "hide story from" settings by console, and I tried this code :
for (let i = 0; i < 300; i++) {
document.getElementsByClassName('wbloks_1')[i]
.addEventListener('click', function (event) {
});
}
unfortunately this doesn’t work anyone has a solution?
div element :
<div data-bloks-name="bk.components.Flexbox" class="wbloks_1" style="pointer-events: none; margin-right: 12px; flex-shrink: 0; align-items: center; flex-direction: row; justify-content: flex-end;"><div data-bloks-name="bk.components.Flexbox" class="wbloks_1" style="pointer-events: none;"><div data-bloks-name="bk.components.Flexbox" role="button" aria-label="Toggle checkbox" class="wbloks_1" style="pointer-events: none; display: none;"><div data-bloks-name="ig.components.Icon" class="wbloks_1" style="-webkit-mask-image: url("https://i.instagram.com/static/images/bloks/icons/generated/circle-check__filled__24-4x.png/219f67ac4c95.png"); -webkit-mask-size: contain; background-color: rgb(0, 149, 246); flex-shrink: 0; width: 24px; height: 24px;"></div></div><div data-bloks-name="bk.components.Flexbox" role="button" aria-label="Toggle checkbox" class="wbloks_1" style="pointer-events: none; display: none;"><div data-bloks-name="ig.components.Icon" class="wbloks_1" style="-webkit-mask-image: url("https://i.instagram.com/static/images/bloks/icons/generated/circle-check__filled__24-4x.png/219f67ac4c95.png"); -webkit-mask-size: contain; background-color: rgba(0, 149, 246, 0.3); flex-shrink: 0; width: 24px; height: 24px;"></div></div><div data-bloks-name="bk.components.Flexbox" role="button" aria-label="Toggle checkbox" class="wbloks_1" style="pointer-events: none;"><div data-bloks-name="ig.components.Icon" class="wbloks_1" style="-webkit-mask-image: url("https://i.instagram.com/static/images/bloks/icons/generated/circle__outline__24-4x.png/2f71074dce25.png"); -webkit-mask-size: contain; background-color: rgb(54, 54, 54); flex-shrink: 0; width: 24px; height: 24px;"></div></div></div></div>
3
Answers
Thanks @Andy Delay:
If you want to add a delay (as per your deleted comment) you could use
setTimeout
to call a function on all of the buttons (event delegation) after a certain time (in milliseconds).To mock this effect here I’ve added a button container that logs the text content of each button when it’s clicked.
The
delayClick
function accepts an array of buttons (from the query selection), grabs the first one, clicks it, and thensetTimeout
is called after a second calling the function again with the rest of the buttons. When there are no buttons left in the array the function returns.Additional documentation
Destructuring assignment
Rest parameters
Put all the elements into an array and remove the first element. Click it, call the function again until you have no elements left. Basic queue.