Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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);
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading