I’m working on a bookmarklet for a Sub reddit and I’m trying to grab all the usernames on a comments page so I can parse them, then come back and update info next to them, similar to what RES does. The author of each comment has a class that is prefixed with Author but then has different stuff at the end of the class name. How would I go about grabbing all the usernames?
Then once I have the list, how would I update each one with an additional icon essentially?
Any suggestions/Tutorials that do similar things would be great.
Edit: I’m not really sure what portions of the markup would be helpful without giving a huge block. Here’s the same question I asked in the Javascript Subreddit. http://www.reddit.com/r/javascript/comments/yhp7j/best_way_to_find_all_the_usernames_on_a_reddit/
You should be able to Inspect the name elements and See what I’m working with.
Currently working with this: http://net.tutsplus.com/tutorials/javascript-ajax/create-bookmarklets-the-right-way/
So I’ve got a Hello World Style Bookmarklet working that checks for Jquery and loads it if it’s not present and just throws an alert.
From a quick look at the page you linked to in your question, it seems as if the mark-up surrounding user-names is as follows (using, presumably, your user-name as an example):
If that’s the case, and the jQuery library is available (again, from your question), one approach is to simply use:
JS Fiddle proof-of-concept.
Or, similarly just use the fact that the user-name seems to be predictably the last portion of the URL in the
aelement’shrefattribute:JS Fiddle proof-of-concept.
Both of these approaches put the
imgwithin theaelement. If you want it before theaelement, then simply use:JS Fiddle proof-of-concept.
References:
each().$.inArray().insertBefore().