[英]Tampermonkey/GreaseMonkey Auto Click Button
我想知道是否有人可以幫助我在 Chrome 上為 Tampermonkey 創建 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();
});
})();
.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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.