使用GreaseKit:如果字符串存在于表单元格中,则单击特定按钮,如果它出现在相同的单元格中

Using GreaseKit: if a string is present in a table cell, then click a specific button IF it appears in the very same cell

本文关键字:单元格 如果 按钮 字符串 GreaseKit 存在 于表 单击 使用      更新时间:2023-09-26

我使用的是GreaseKit(所以JavaScript)

步骤#1查找字符串&步骤2单击按钮

当这个HTML页面加载时,如果下列任意一个:

  • Only 3 Left
  • Only 2 Left
  • Only 1 Left

出现在表格单元格中,并且在同一单元格中存在class="PrmryBtnMed"按钮,然后使用el.click();

单击按钮

我们可以看看<tr>标签里面吗?

如果没有,另一种方法可能是单击紧接着出现在所需字符串下面或后面的第一个按钮。

更新:感谢@Bergi,似乎我们可以使用:var LookInCells = document.getElementsByTagName('tr');

关于按钮:查找哪个属性?

<a href="/gp/wine/taste-next-123/" class="PrmryBtnMed" id = "product-B00123456"><span>Send me this item</span></a>

那么,考虑按钮的属性

这些总是相同的:

  • class="PrmryBtnMed"
  • <span>Send me this item</span></a>

这些总是不同的,所以不妨忽略:

  • ,链接指向(例如a href="/gp/wine/taste-next/")
  • id将始终为'id = "product-B00123456"'

根据@Bergi的指导,我正在尝试这个!

var LookInCells = document.getElementsByTagName('tr');
var MyString =  ['Only 3 Left', 'Only 2 Left', 'Only 1 Left']
for(var i = 0;i < LookInCells.length;i++){
}
var inPage = document.documentElement.innerHTML.indexOf(MyString) > 0,
// el = document.querySelector(".PrmryBtnMed");
el = document.getQuerySelectorAll("td:last-child a.PrmryBtnMed")    
if (inPage && el) el.click();
相关文章: