Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:37:04+00:00 2026-06-09T20:37:04+00:00

I’m working on a bookmarklet for a Sub reddit and I’m trying to grab

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:37:06+00:00Added an answer on June 9, 2026 at 8:37 pm

    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):

    <a href="http://www.reddit.com/user/DiscontentDisciple" class="author id-t2_4allq" >DiscontentDisciple</a>
    

    If that’s the case, and the jQuery library is available (again, from your question), one approach is to simply use:

    var authors = [];
    
    $('a.author').html(
        function(i, h) {
            var authorName = $(this).text();
            if ($.inArray(authorName, authors) == -1) {
                authors.push(authorName); // an array of author-names
            }
            return '<img src="path/to/' + encodeURIComponent(authorName) + '-image.png" / >' + h;
        });
    
    console.log(authors);
    

    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 a element’s href attribute:

    var authors = [];
    
    $('a.author').html(
        function(i, h) {
            var authorName = this.href.split('/').pop();
            if ($.inArray(authorName, authors) == -1) {
                authors.push(authorName);
            }
            return '<img src="http://www.example.com/path/to/' + authorName+ '-image.png" />' + h;
        });
    
    console.log(authors);
    

    JS Fiddle proof-of-concept.

    Both of these approaches put the img within the a element. If you want it before the a element, then simply use:

    // creates an 'authors' variable, and sets it to be an array.
    var authors = [];
    
    $('a.author').each( // iterates through each element returned by the selector
        function() {
            var that = this, // caches the this variable, rather than re-examining the DOM.
                // takes the href of the current element, splits it on the '/' characters,
                // and returns the *last* of the elements from the array formed by split()
                authorName = that.href.split('/').pop();
    
            // looks to see if the current authorName is in the authors array, if it *isn't*
            // the $.inArray returns -1 (like indexOf())
            if ($.inArray(authorName, authors) == -1) {
                // if authorName not already in the array it's added to the array using
                // push()
                authors.push(authorName);
            }
    
            // creates an image element, concatenates the authorName variable into the
            // src attribute-value
            $('<img src="http://www.example.com/path/to/' + authorName+ '-image.png" />')
                // inserts the image before the current (though converted to a jQuery
                // object in order to use insertBefore()
                .insertBefore($(that));
        });
    
    console.log(authors);
    ​
    

    JS Fiddle proof-of-concept.

    References:

    • each().
    • $.inArray().
    • insertBefore().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.