I am trying to create a bookmarklet that performs simple functions across different webpages. The idea is that it would be in an easy to find location (on the bookmark bar) and perform the "standard function" on a given page. Instead of looking for a hyperlink or a submit button, I can rely on the bookmarklet to do its duty.
As someone that does not code in javascript, I am having trouble getting the bookmarklet to work on more than one item/page. I started by using the getElementById function successfully
javascript:(function () {
var i = document.getElementById("contactSeller").click()
})()
On another page, there is a button with the ID "sndBtn". Adding another click() function to the code with the second ID, however, doesn't work.
javascript:(function () {
var i = document.getElementById("contactSeller").click();
var m = document.getElementById("sndBtn").click()
})()
As far as I can tell it is because getElementById can only work once on a page. (Removing the first function makes the second one work). Other users have suggested recursive functions with CSS or jQuery but I had little luck getting them to work as bookmarklets.
Can someone help construct a simple function that will run through a list of clicks? It would be nice to have the ability to follow hyperlinks, submit forms, and click buttons i.e. so it is not only a recursive script of the same function. Each of the elements on each page seems to have unique ID's.
Links GetElementByID - Multiple IDs
https://gist.github.com/aseemk/5000668
https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll