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 308917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:41:39+00:00 2026-05-12T07:41:39+00:00

A blog I read has some annoying commenters. I thought I would try my

  • 0

A blog I read has some annoying commenters. I thought I would try my hand at Greasemonkey to turn them off.

The basic structure of the HTML is simple – a comment looks something like this:

<li>
  <cite>user name ...</cite>
  comment text
</li>

So with that in mind, I bashed my head against the keyboard for a while until this dropped out:

var killlist = /user1|user2/;

var comments = document.getElementsByTagName('li');

if (comments.length) {
  for ( var i = 0; i < comments.length; i ++ ) {
    var comment = comments[i];
    var cites = comment.getElementsByTagName('cite');
    if (cites.length) {
      var cite = cites[0];
      var title = cite.textContent;
      if (killlist.test(title)) {
        comment.parentNode.removeChild(comment);
      }
    }
  }
}

window.alert('Done!')

(the window.alert is just so I know if the script runs to completion)

This mostly works. e.g. on one test page, it removed 13 of 16 posts by one of the users. I tried replacing the removeChild line with this:

comment.style.visibility = 'hidden';

That appears to get everything, but at the expense of leaving great empty spaces where the comments would have been.

I’m a complete javascript newbie, so can anyone see anything obvious I’m doing wrong?

  • 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-05-12T07:41:40+00:00Added an answer on May 12, 2026 at 7:41 am

    You should be able to fix it by reversing the order of your for loop and deleting elements from the end of the comments array first:

    for ( var i = comments.length - 1; i >= 0; i-- )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some months ago I read a blog post which had a comparison of different
Read in some blog that GC in Android happens on main(UI) thread, this may
I recently read a blog in Nodejitsu and I am wondering how this piece
I've read the blog post at letitcrash.com about Play-mini and Akka ( this one
I just read a blog which says ...methods that couldn’t be inlined previously because
I'm looking into exception handling in python and a blog post I read differentiated
I read at Scottgu blog about using OutputCache for a function but this didn't
I've read Neal Gafter's blog on the subject and am still unclear on a
I read this comment in the OpenID post on the stackoverflow blog. Kibbee says
I read at a few places (in the doc and in this blog post

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.