javascript点击所有svg按钮修改请求紧急

问题描述 投票:0回答:2

我试图点击所有的白心,只忽略已经完成的红心。 我正在尝试添加一个 if 语句来检查但不确定如何。

这里是我的代码,点击所有的心都变成红色,但由于页面上的延迟加载,在一段时间后停止点击,所以我需要重新点击它,以便它恢复点击。

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);

}

好的,这是来自浏览器的 javacode for red hearts 已经完成。

<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

现在是白心

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

ok 所以现在我想使用我的代码并添加一个 if 语句来检查心是否有 currentColor 然后使红色

这是我需要修改的代码。需要在循环代码中添加 if 语句来检查 currentColor 并点击

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);

}
javascript
2个回答
0
投票

尝试以下方法:

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);
  }
}

0
投票
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);
  }
}

mohammad 非常感谢你它工作得很好

© www.soinside.com 2019 - 2024. All rights reserved.