javascript click all svg button modification request urgent

i am trying to click on all white hearts only ignoring the red hearts that was done already.
am trying to add a if statement to check but not sure how.

here is the code i have that clicks all hearts to red but stops clicking after certain period of time due to lazy loading on page so i need to re-click it so it resumes clicking.

const inputs =  document.querySelectorAll('.tiktok-1wyxwrs-DivLikeWrapper, .tiktok-ezxoskx1-DivLikeWrapper,.tiktok-1e3qwdr-DivLikeWrapper-StyledLikeWrapper,.tiktok-1e3qwdr-DivLikeWrapper-StyledLikeWrapper,.tiktok-1e3qwdr-DivLikeWrapper-StyledLikeWrapper')

for (let i = 0; i < inputs.length; i++) {

  setTimeout(function() {
    inputs[i].click()
  }, 1000 * i);

}

ok so here is the javacode from browser for red hearts already done.

<svg width="20" data-e2e="" height="20" viewBox="0 0 24 24" fill="rgba(254, 44, 85, 1)" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#HeartFill_clip0)"><g filter="url(#HeartFill_filter0_d)"><path

and now white hearts

<svg width="20" data-e2e="" height="20" viewBox="0 0 48 48" fill="currentColor" xmlns="http://www.w3.org/2000/svg">

ok so now i want to use my code and add a if statement to check if hearts have currentColor then make red

this is my code that needs modification. need to add if statement to check for currentColor in loop code and click

const inputs =  document.querySelectorAll('.tiktok-1wyxwrs-DivLikeWrapper, .tiktok-ezxoskx1-DivLikeWrapper,.tiktok-1e3qwdr-DivLikeWrapper-StyledLikeWrapper,.tiktok-1e3qwdr-DivLikeWrapper-StyledLikeWrapper,.tiktok-1e3qwdr-DivLikeWrapper-StyledLikeWrapper')

for (let i = 0; i < inputs.length; i++) {

  setTimeout(function() {
    inputs[i].click()
  }, 1000 * i);

}

>Solution :

Try the below:

const inputs =  document.querySelectorAll('.tiktok-1wyxwrs-DivLikeWrapper, .tiktok-ezxoskx1-DivLikeWrapper,.tiktok-1e3qwdr-DivLikeWrapper-StyledLikeWrapper,.tiktok-1e3qwdr-DivLikeWrapper-StyledLikeWrapper,.tiktok-1e3qwdr-DivLikeWrapper-StyledLikeWrapper')

for (let i = 0; i < inputs.length; i++) {
  if (inputs[i].querySelector('svg').getAttribute('fill') === 'currentColor') {
    setTimeout(function() {
      inputs[i].click()
    }, 1000 * i);
  }
}

Leave a Reply