My goal is to develop a bookmarklet that can perform various functions on different webpages with ease. The concept involves placing it in a convenient location, such as the bookmark bar, and executing a "standard function" on a particular page. Instead of searching for a hyperlink or submit button, I can rely on the bookmarklet to carry out its task.
Despite not being proficient in JavaScript, I am facing challenges when attempting to make the bookmarklet work across multiple items/pages. Initially, I achieved success using the getElementById function like this:
javascript:(function () {
var i = document.getElementById("contactSeller").click()
})()
However, on another page where there is a button with the ID "sndBtn", adding another click() function to the code did not yield the desired result:
javascript:(function () {
var i = document.getElementById("contactSeller").click();
var m = document.getElementById("sndBtn").click()
})()
It appears that the issue lies in the fact that getElementById can only be used once on a page. (Removing the first function allows the second one to work). Some users have recommended employing recursive functions with CSS or jQuery, but I struggled with implementing them effectively as bookmarklets.
I am seeking assistance in creating a simple function that can iterate through a list of clicks. It would be beneficial to have the capability to follow hyperlinks, submit forms, and click buttons – essentially, more than just a repetitive script of the same function. Each element on every page seems to possess unique IDs.
Links GetElementByID - Multiple IDs
https://gist.github.com/aseemk/5000668
https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll