I was wondering if anyone could help me create JavaScript for Tampermonkey on Chrome that will create button for click another button
And here is the js path for the button:
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. Make sure your tampermonkey script starts after the document has loaded and your queryselector is correct.
(() => { 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.