简体   繁体   English

Tampermonkey/GreaseMonkey 自动点击按钮

[英]Tampermonkey/GreaseMonkey Auto Click Button

I was wondering if anyone could help me create JavaScript for Tampermonkey on Chrome that will create button for click another button我想知道是否有人可以帮助我在 Chrome 上为 Tampermonkey 创建 JavaScript,它将创建用于单击另一个按钮的按钮

And here is the js path for the button:这是按钮的 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();
  });
})();

.click() works. .click()有效。 Make sure your tampermonkey script starts after the document has loaded and your queryselector is correct.确保你的 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM