【问题标题】:Tampermonkey/GreaseMonkey Auto Click ButtonTampermonkey/GreaseMonkey 自动点击按钮
【发布时间】:2021-06-18 03:02:43
【问题描述】:

我想知道是否有人可以帮助我在 Chrome 上为 Tampermonkey 创建 JavaScript,该 JavaScript 将创建用于单击另一个按钮的按钮

这里是按钮的js路径:

document.querySelector("#root > div.sc-jtiXyc.jireel > div:nth-child(1) > div.product > div.container > div.create-listing > div.create-listing-btn-bar > button")
(function() {
  function add() {
    document.querySelector("#root > div.sc-jtiXyc.jireel > div:nth-child(1) > div.product > div.container > div.create-listing > div.create-listing-btn-bar > button").click();
  }

  var btn = document.createElement("BUTTON");
  btn.innerHTML = "Add to listing";
  document.body.appendChild(btn);
  document.querySelector("body > button").style.position = "fixed";
  btn.addEventListener('click', () => {
    add();
  });
})();

【问题讨论】:

  • 使用yourButton.click()有什么问题?
  • 当我尝试它时,它不起作用
  • 无法复制。

标签: javascript tampermonkey


【解决方案1】:

.click() 有效。确保您的 Tampermonkey 脚本在文档加载后启动并且您的查询选择器正确。

(() => {
  const button = document.createElement("button");
  button.innerText = "I'm the second button";
  button.addEventListener("click", () => {
    console.log("you clicked the second button");
    document.querySelector("button#og").click();
  });
  document.body.appendChild(button);
})()
<button onclick="console.log('you clicked the og button')" id="og">
  OG Button
</button>

【讨论】:

    猜你喜欢
    • 2018-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    相关资源
    最近更新 更多