I've made a script that auto-click a button on load. This button will add an item on cart and also make a pop-up. After you click the close pop-up icon, the page will be refreshed and triggering auto-click loop. Is there a way to bypass this?
my script:
var a = document.getElementById("discount");
if (discount.dataset.value === "TEST"){for ( var i = 0; i < 50; i++ ) {
document.getElementById("clickMe").click();
}}
Check if this is working for you!
if (!localStorage.getItem('autoClick')) { // check if code already ran
// if not then do the clicks
var a = document.getElementById("discount");
if (discount.dataset.value === "TEST"){for (
var i = 0; i < 50; i++ ) {
document.getElementById("clickMe").click();
}}
localStorage.setItem('autoClick', true); // save that you did the clicks
} else {
// if you did the click and pop-up refreshed the page,
// let's remove the state so you can auto click again on next refresh
localStorage.removeItem('autoClick');
}
Try use 'break' in you 'for loop'.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break