59

IMPORTANT - Read before using...

This script is not meant to be a solution for bad behavior on Stack Exchange sites. If you feel somebody is violating the rules of this site, please contact the team via the "contact" link.


Update (Jan 19, 2023):

A user in the comments requested an updated version. Here's an approach which masks comments belonging to specified user IDs:

(function() {
    'use strict';

    const ids = [-1, 284996, 216691];
    const selector = ids.map(( id ) => `[data-comment-owner-id="${id}"]`);
    const styles = `
        ${selector.map( s => `${s} .comment-copy > *`)} {
            color: transparent;
            background: rgba(0, 0, 0, 0.15);
        }
    `;

    document.head.appendChild(
        document.createElement("style")
    ).innerHTML = styles;

    function maskComments () {
        document.querySelectorAll(selector.join(',')).forEach(createMask);
    }

    function createMask ( element ) {
        const commentCopy = element.querySelector(".comment-copy");
        for ( const child of commentCopy.childNodes ) {
            if ( child.nodeName === "#text" && child.nodeValue !== " " ) {
                const fragment = document.createDocumentFragment();
                for ( const token of child.nodeValue.split(" ") ) {
                    const span = document.createElement("span");
                    span.textContent = token;
                    fragment.append(span, " ");
                }
                commentCopy.replaceChild( fragment, child );
            }
        }
    }

    maskComments();

})();

This approach preserves the actual comments (which can be revealed via selection) while masking their content. Here's an example:

enter image description here


Remove any instance of a particular user or group of users from your Stack Overflow experience with this Greasemonkey script. Just place their names in the userids array and listen as the noise decreases.

Updates:

  • Tuesday, July 14, 2009

    The script would remove any questions that were edited by anybody within your ignore-users list. This has been fixed. Additionally, avatars representing your ignored-users will be replaced with random avatars. Any remaining references to any names in your ignore-list will be replaced with 'unknown (Google),' a common title for unrecognizable users on Stack Overflow. Script was not operating properly on community-wiki posts.


Submit your improvements...

var userids = ['Username 1', 'Username 2'];

(function() {
    function GM_wait() {
        if(typeof unsafeWindow.jQuery == 'undefined') {
            window.setTimeout(GM_wait,100);
        }
        else {
            $ = unsafeWindow.jQuery; letsJQuery();
        }
    }
    GM_wait();
    function letsJQuery() {
        $.each(userids, function() {

            $(".post-signature:contains('"+this+"')").remove();

            $("div.answer").each(function() {
                var paCount = $(this).find(".post-signature").length;
                if (paCount == 0) { $(this).remove(); }
                if (paCount == 1 && ($(this).find(".post-signature:contains('community wiki')").length == 1)) { $(this).remove(); }
            });

            $("a.comment-user:contains('"+this+"')").closest("tr.comment").remove();
            $("a[rel='canonical']:contains('"+this+"')").html("unknown (Google)");

            var randHash = "";
            for(var i = 0; i < 4; i++) { randHash += Math.floor(Math.random()*0x100000000).toString(16); }

            $(".user-gravatar32>a[href*='"+this.replace(/\s/g,"-").toLowerCase()+"']>img")
              .attr("src", "http://www.gravatar.com/avatar/"+randHash+"?s=32&d=identicon&r=PG");
        });
    }
    $(window).ajaxComplete(function() {
        letsJQuery();
    });
})();
11
  • 2
    To hide questions as well add this line: $('.question-summary:contains("'+this+'")').remove();
    – wheresrhys
    Commented Dec 21, 2009 at 20:37
  • 1
    Would there be any way to modify this script so that you can also ignore a user's comments that show up on your "Most Recent Responses" page?
    – kekekela
    Commented Aug 4, 2010 at 15:54
  • 2
    an ignore or post rating threshold filter facility also obviates the need for moderators. the community could be allowed either collectively (post-rating filter) or individually (ignore lists) to manage their own community experience. it works well in other places. Commented Jul 17, 2012 at 18:29
  • Thanks for this. I come from Usenet and love a good killfile. I added this to the paCount definition: .filter(function(){ return $(this) .find("a[href*=revisions]:contains(edited)") .length == 0; }) - it's needed to hide answers that a killfiled user posted and edited.
    – user281099
    Commented Jun 17, 2017 at 19:57
  • Referenced from How can I hide all content from a specified user?. Commented Sep 11, 2017 at 17:33
  • 3
  • And if two users have the same name? Wouldn’t it be better to take the “ids” instead of “names”? Commented Nov 15, 2019 at 1:04
  • 2
    When you're not displaying posts by some users, you risk missing important context provided by them or may post things that were already posted by them. This will cause confusion for you and others.
    – allo
    Commented Nov 15, 2019 at 16:00
  • Is this still working, I just want it removed from comments rather than posts. Commented Jan 15, 2023 at 1:35
  • @ArchimedesTrajano I just updated the post with a newer approach.
    – Sampson
    Commented Jan 19, 2023 at 17:22
  • 1
    You may want to add the meta block so it's complete to copy and paste. But thanks nonetheless Commented Jan 19, 2023 at 19:32

8 Answers 8

48

I believe this XKCD comic below demonstrates perfectly why some of us need this script:

Alice: Are you coming to bed? / Bob: I can't. This is important. / Alice: What? / Bob: Someone is *wrong* on the internet.

And even more relevant is the alttext: "What do you want me to do? LEAVE? Then they'll keep being wrong!"

0
10

I actually find this thread pretty offensive. I would express myself by voting "offensive", but unfortunately my ♦ means that it would delete the entire post — which isn't my intention.

Posting a script to ignore somebody by name is clearly inappropriate.

Choosing to use a script to ignore any set of users is frankly blinkered; you destroy the entire context of the things you are interested in. I won't try to stop you... but... why?

Re the point (comments) about empowering "folks who can't do anything about other users"; that is ridiculous. You are all empowered; use the "flags", or e-mail the team. However, you will understand that when an intervention is required, it won't be done in theatre for your viewing pleasure. That doesn't mean that things are ignored.

Also; we all know who the target of your ire is. I've been catching up on a few hours of missed posts, and frankly his actions are not the worst of today — quite far from it. None of us are angels, but let's stay in reality.

It is also possible, upon raising a flag, that the moderators will reserve the right to assess the situation and decide that no action is appropriate at the moment. That is purely a "general policy" comment, and shouldn't be taken as an indication of any specific event (it can't be: I wasn't directly involved in today's fun).

26
  • 10
    @Marc - What I was getting at in my comment is that there are folks who take up quite a bit of my time either defending actions or other things that takes away from helping others. I personally get way to wrapped up in what some users do on the site to the point where it really does take away from what I can offer to others or take in myself. I also personally think the moderators have enough on their plates (like full time jobs) and they don't need to put up with constant complaints. So at the end of the day if posts are hidden from me, I'm not adding to the problem myself...
    – RSolberg
    Commented Jul 7, 2009 at 23:01
  • 3
    Re writing scripts: note "I won't try to stop you" Commented Jul 7, 2009 at 23:02
  • 3
    I agree with Marc. If stackoverflow was a forum with offensive material it'd make sense, but at worst it's got a few language wars and that's about it. Ignore user seems a little bit of an adolescent feature
    – Chris S
    Commented Jul 14, 2009 at 16:46
  • 40
    Fwiw, my personal experience is that the current facilities (i.e. flagging and emailing) are not good enough for anything but the most blatant or high visibility comments. Persistent, drawn out abuse is below the radar. My core argument for this feature is that if it helps make someone's life on SO better, then why not?
    – bananakata
    Commented Jul 14, 2009 at 18:44
  • 16
    @annakata I totally agree. There is some small subset of users who are really making the experience less enjoyable and useful. I don't see the problem. If SO won;t address it then why not do it at the client side?
    – tim
    Commented Jul 22, 2009 at 21:25
  • 6
    @annakata: you've summed it up perfectly. I enjoy using both SO and meta, in general. I try to ask good questions, I try to give good answers. None of that will be affected by my ability to hide a particular user. What happens now is that I try to restrain myself from lashing out every time I see a particular user mouthing off. I can honestly say that I think it would improve the experience quite a bit to be able to hide him.
    – beska
    Commented Oct 21, 2009 at 21:51
  • 9
    If you have someone constantly trolling your threads, reporting doesn't seem to do much. I like having this option so I can just ignore my personal SO stalker and not get sucked into arguing with him.
    – kekekela
    Commented Aug 4, 2010 at 2:19
  • 6
    I really don't think anyone can criticize what another person is doing on their own computer to make their own experience better for themselves. They are not applying a ban to nor censoring people for everyone else to see and the person being filtered doesn't even know. So how can there be anything offensive or wrong about it? The comments against this idea are on the same level as criticizing a person for choosing to read books of one genre, but choosing to avoid another. It's personal preference, non imposing and private. What business is that of anyone else?
    – user159773
    Commented Aug 6, 2011 at 23:12
  • 5
    I personally think this is a fantastic idea. I was banned for a few days for completely losing my cool on a person that was harassing me, going through all my comment history and posting things to bother me, but as someone else mentioned here this was not obvious enough so it was under the radar. It's hard to ignore when it's constant so if I can just keep myself from seeing any of the crap that makes for a bad experience or could sucker me into a conflict that would get me in trouble, then I say amen to that.
    – user159773
    Commented Aug 6, 2011 at 23:14
  • 14
    why should the moderators be the judge of what's offensive or disruptive TO ME. let people use the site however they like. this script is great. Commented Jul 17, 2012 at 18:03
  • 4
    @MarcGravell I really do wish this wasn't the SE policy on the matter. There is currently no process I, as someone who is frequently pestered and targeted by another user with downvotes, comments inviting discussion, etc, can pursue to deal with the situation outside of quitting SE. One user - who has even been banned before - can cause many others to become less interested and/or motivated to post an on entire SE site (such as The Workplace) because they make the entire experience obnoxious and there is no resolution... :(
    – enderland
    Commented Jul 4, 2013 at 3:45
  • 2
    @enderland: I'm very familiar with the situation you're referring to; while it's certainly very unfortunate that the moderators felt unable to handle it effectively, I disagree that ignoring the user in question would've helped matters any - indeed, this would've effectively given him license to bother new users without any oversight! Your best option as a user is to flag rude or obnoxious actions; trust me, moderators have a much easier time dealing with this stuff when there's a clear history of abuse to follow.
    – Shog9
    Commented Jul 4, 2013 at 19:09
  • 2
    @Shog9 the thing is, I like to and spend time on the SE network because it's enjoyable. Having to make war against someone who is allowed to be a troll because of how the SE rules work is not enjoyable. Having that as the "best option" frankly speaking means ignore via a script like this IS the best option. Alas, if I only used FF...
    – enderland
    Commented Jul 4, 2013 at 19:17
  • 3
    using a script to ignore users would destroy the context of things you *are* interested in So just implement a toggle (default hide, click “show…”) If you go to this extreme, then you’re not interested in a user’s unrelated, combative, argumentative posts and won’t mind missing a worthwhile post from them once in a while (avoiding their guff is worth the loss). I won't try to stop you, but why? Some of us have OCD and thus have great (even painful) difficulty ignoring a confrontation (especially if we’re right), so simply not seeing it would make it easier to “move on”.
    – Synetech
    Commented Sep 7, 2013 at 19:25
  • 2
    "why?" because some users are obsessive and irritating and have nothing of value to add, they also go and trash questions with their BS and just bait flame war. There's nothing to be said or read from these people.
    – shinzou
    Commented Jul 10, 2015 at 12:01
8

I like playing devil's advocate, so I'm going to raise an issue here for discussion that I don't think has really been covered yet...

Ignoring users via a script like this could be construed as incredibly selfish, since it doesn't really assist the larger community. If there is someone on Stack Overflow behaving in a manner that you truly feel is insulting or damaging to the site as a whole, why wouldn't you take action to inform or contact a moderator?

Using a script to ignore people doesn't stop what they're doing. They are still doing the things you believe are damaging to the site, but you're just pretending they're not. So you're basically letting Stack Overflow get abused, instead of doing the responsible thing and pointing it out.

Shouldn't people who enjoy Stack Overflow be willing to give a little something back in the form of oversight and moderation, even if it means occasionally having to see things that annoy you? Problems generally don't get fixed by just turning a blind eye to them.

7
  • 3
    @gnovice: I would go out on a limb and suggest that this script is a last resort for some users... The things you've talked about have been done.
    – RSolberg
    Commented Jul 14, 2009 at 15:55
  • 7
    @gnovice - This script is for those who have exhausted all other methods.
    – Sampson
    Commented Jul 14, 2009 at 16:00
  • 1
    @gnovice - you are right, but no one is doing anything about it and all attempts to resolve it are ignored/declined. So we have to do it individually.
    – tim
    Commented Jul 22, 2009 at 21:26
  • 5
    Maybe because you've got the "ignore flags from this guy" tag. Just because the moderators feel the behavior of people harassing you is A-OK doesn't mean you should be stuck having to put up with it.
    – anon
    Commented Feb 23, 2011 at 23:29
  • 13
    If there is someone on SO behaving in a manner that you truly feel is insulting or damaging to the site as a whole, why wouldn't you take action to inform or contact a moderator? It may be hurtful to a user, but not “damaging” to the site. There are lots of times where an argument or something makes someone uncomfortable but not everybody. It’s not worth getting mods involved, but that doesn’t mean users who are affected by it should have to see it. Ignoring users via a script like this could be construed as incredibly selfish That’s the point. This would let you choose.
    – Synetech
    Commented Sep 7, 2013 at 19:43
  • 1
    And when that person is a mod? You're basically screwed. Commented Dec 23, 2021 at 14:08
  • 1
    I absolutely agree that StackExchange users should ideally be willing to give something back, but I'm entirely content with my level of contributions, so I feel no obligation to include "suffering users who are making my experience here less pleasant" as a part of my "something". A user also does not need to be breaking rules, or be insulting or harmful to the site as a whole, for me to want to block them. They just need to be making my life measurably worse in some way, and to have shown no signs of changing the behaviour which is responsible for that.
    – phils
    Commented Jul 9, 2023 at 16:28
6

I just needed this feature today, yet it doesn't work anymore due to changes on Stack Overflow. So I made some tweaks to fix it:

  1. Removed unsafewindow (I'm not sure what it does, but the script works without it)

  2. Look for the user to block based on userid instead of username.

    Note that userid could change on different sites, so you may need add multiple entries!

var userids = ['895245'];

(function() {
    'use strict';

    // Your code here...
    function letsJQuery() {
        $.each(userids, function(){

            // Comment
            var hide_comment_user_name = $("a.comment-user[href*='"+this+"']");
            //hide_comment_user_name.closest("li.comment").remove(); // Remove ENTIRE comment section (of this user)

            hide_comment_user_name.html("DELETED");
            hide_comment_user_name.attr("href", "");

            // Answer
            var div_post_signature = $("div.post-signature:has(div.user-details:has(a[href*='"+this+"']))").find("div.user-info");
            //div_post_signature.closest("div.answer").remove(); // Remove ENTIRE answer section (of this user)
            //div_post_signature.remove();                       // Remove Author section

            div_post_signature.removeClass("user-hover"); // Disable popup

            var hide_answer_author_user_name = $(div_post_signature).find("div.user-details").find("a");
            hide_answer_author_user_name.html("DELETED");
            hide_answer_author_user_name.attr("href", "");

            var randHash = ""; // for gravatar
            for(var i = 0; i < 4; i++) { randHash += Math.floor(Math.random()*0x100000000).toString(16); }
            var hide_answer_author_user_avatar = $(div_post_signature).find("div.user-gravatar32").find("a");
            hide_answer_author_user_avatar.attr("href", "");
            hide_answer_author_user_avatar.find("div.gravatar-wrapper-32").find("img").attr("src", "http://www.gravatar.com/avatar/"+randHash+"?s=32&d=identicon&r=PG");

        });
    }
    $(window).ajaxComplete(function() {
        letsJQuery();
    });
})();
1
  • 1
    See stackoverflow.com/questions/10824697/… for more info on unsafeWindow. The script itself works without it, but additional functionality coming from other sources (other scripts running in tandem) potentially won't work without it. Note however that the property is also not recommended for use anyway as it is not secure.
    – TylerH
    Commented Nov 14, 2019 at 15:18
3

I feel it is the place of moderators to punish those who misuse the site and while you have every right to control what appears on your computer screen, I feel that it breaks the point of the site if you are able to block content from specific contributors.

3
  • 7
    What exactly would you propose then? The site experience has been broken for some users because of what has been happening already....
    – RSolberg
    Commented Jul 9, 2009 at 15:26
  • 2
    @Jonathan: Yes, I totally understand and as a temporary short-lived fix, I think it's acceptable. I just think that long term, this wouldn't be a constructive solution. The real fix is to tackle the problem as a community - it's wrong to assume that just because it's broken (in RSolberg's words), we should do anything we can to fix it on our own. Let's work together to push the scumbags out.
    – Jeff Yates
    Commented Jul 10, 2009 at 3:36
  • 3
    I feel it is the place of moderators to punish those who misuse the site That makes a lot of extra work which may not be necessary and could be avoided by simply ignoring it. This function lets users for whom it matters enough, to do exactly that without adding to the moderators’ queue. Plus not everything that is offensive to someone is offensive to everyone, and so might not be hidden; this lets you choose your level of sensitivity. If something is so bad that it requires moderator attention, then others will end up quickly flagging it and getting it removed.
    – Synetech
    Commented Sep 7, 2013 at 19:38
3

To replace the user's gravatar with a random gravatar:

var randHash = "";
for(var i = 0; i < 4; i++)
  randHash += Math.floor(Math.random()*0x100000000).toString(16);
$(".user-gravatar32>a[href*='"+this.replace(/\s/g,"-").toLowerCase()+"']>img")
  .attr("src", "http://www.gravatar.com/avatar/"+randHash+"?s=32&d=identicon&r=PG");

That of course goes inside the $.each loop.

0
2

Here's another variation. It's based on the "Update (Jan 19, 2023)" code in the question, and additionally tries to hide questions from question lists and mask question text if you wind up looking at one anyway. The code could be better, but it's functional.

// ==UserScript==
// @name        StackExchange user block
// @namespace   my-stackexchange-block-user
// @include     https://stackoverflow.com/*
// @include     https://foo.stackexchange.com/*
// @version     1.1
// ==/UserScript==

// Instructions:
//
// UserScript for use with FireMonkey and similar:
// https://addons.mozilla.org/en-GB/firefox/addon/firemonkey/
//
// Edit both the @include headers and the domain_user_ids map.
//
// For more information, see:
// https://meta.stackexchange.com/questions/3360/ignore-users-script

(function() {
    'use strict';

    const domain_user_ids = {
        'stackoverflow.com': [
            12345678,
            23456789,
            34567890,
        ],
        'foo.stackexchange.com': [
            12345,
            23456,
        ],
        'undefined': []
    };
    if (typeof(domain_user_ids[document.domain]) === 'undefined') {
        return;
    }

    const user_ids = domain_user_ids[document.domain] || [];
    if (!user_ids) {
        return;
    }

    // Question selector.
    const qselector = user_ids.map((id) => `[data-user-id="${id}"]`).join(',');

    // Question and Answer body text selector and CSS.
    const qauselector = user_ids.map(
        (id) => `.post-layout .post-signature.owner .user-info .user-details a[href^="/users/${id}/"]`
    ).join(',');

    const quastyles = `
        .my-mask, .my-mask * {
            color: transparent !important;
            background: var(--black-075) !important;
        }
    `;

    // Comment selector and generated CSS.
    const cselector1 = user_ids.map((id) => `[data-comment-owner-id="${id}"]`);
    const cselector2 = cselector1.join(',');
    const cstyles = `
        ${cselector1.map(s => `${s} .comment-copy > *`)} {
            color: transparent;
            background: rgba(0, 0, 0, 0.15);
        }
    `;

    document.head.appendChild(
        document.createElement("style")
    ).innerHTML = quastyles + cstyles;

    function blockUsers() {
        document.querySelectorAll(qselector).forEach(hideQuestions);
        document.querySelectorAll(qauselector).forEach(maskPost);
        document.querySelectorAll(cselector2).forEach(maskComments);
    }

    function hideQuestions(element) {
        // Naively we would simply remove this post:
        // element.closest('.s-post-summary').remove();
        //
        // However S.E. doesn't provide sufficient data in the
        // markup to reliably identify the author of the
        // question (only one user is shown, and it is often the
        // user who last answered or modified the question).
        // Consequently this approach would hide questions asked
        // by other users but answered or edited by blocked
        // users, and would fail to hide 'active' questions from
        // blocked users which have been answered or edited by a
        // non-blocked user.
        //
        // We *can* treat the special case of "0 answers" this
        // way, however.  This is useful, as the "modified"
        // indicator does not differentiate between "user
        // modified the question" and "user modified an answer",
        // whereas this special case is unambiguous in that
        // regard.
        const summary = element.closest('.s-post-summary');
        if (summary.querySelector('.s-post-summary--stats-item[title="0 answers"]')) {
            summary.remove();
            return;
        }
        // My impression is that we would need to start firing
        // off API requests for lists of question IDs from each
        // user in order to reliably detect the correct
        // questions, which is a lot more complicated than this.
        //
        // As a lower-effort workaround, we manipulate only the
        // summaries which state that a blocked user "asked" or
        // "modified" the question.  We keep (display) questions
        // that a blocked user has "answered" on the basis that
        // the question itself may be worth looking at.  If it
        // turns out that a blocked user (maybe the same user)
        // also asked that question then c'est la vie -- the
        // maskPost() function will at least do its part if we
        // visit it.
        let time = element.closest('.s-user-card').querySelector('.s-user-card--time');
        const link = time.querySelector('.s-link');
        if (link) {
            time = link;
        }
        const text = Array.from(time.childNodes).find(n => n.nodeType === Node.TEXT_NODE).textContent.trim();
        if (text === 'asked') {
            summary.remove();
        }
        else if (text === 'modified') {
            // We can't tell whether the blocked user asked or
            // answered this question.  If we are blocking the
            // user for an excessive number of low-quality
            // questions then there's a pretty good chance that
            // they asked the question, but we err on the side
            // of caution and display it -- however we present
            // it as if it were tagged with one of our "ignored"
            // tags in order to de-emphasise it.
            summary.classList.add('s-post-summary__ignored');
        }
    }

    function maskPost(element) {
        // Even if we can't always prevent links to these
        // questions from being displayed, we can at least make
        // it clear that it's not worth reading if we wind up
        // looking at one of them.
        element.closest('.post-layout').querySelector('.s-prose').classList.add('my-mask');
    }

    function maskComments(element) {
        const commentCopy = element.querySelector(".comment-copy");
        for (const child of commentCopy.childNodes) {
            if (child.nodeName === "#text" && child.nodeValue !== " ") {
                const fragment = document.createDocumentFragment();
                for (const token of child.nodeValue.split(" ")) {
                    const span = document.createElement("span");
                    span.textContent = token;
                    fragment.append(span, " ");
                }
                commentCopy.replaceChild(fragment, child);
            }
        }
    }

    // Do the thing.
    blockUsers();
})();
2
  • Important note: S.E. doesn't provide sufficient data in the markup to reliably identify the question author in lists of questions. This script nevertheless does what it can based on the user who is mentioned at the time, but it's not perfect. See the hideQuestions() function comments for details.
    – phils
    Commented Jul 9, 2023 at 14:11
  • 1
    You may occasionally observe the question list flicker upon loading as it removes a question which had been momentarily visible, and feel a warm glow of happiness knowing that your day has been made just a little bit better.
    – phils
    Commented Jul 9, 2023 at 14:31
1

Add the following to subscribe to the global Ajax complete event to handle the comments.

$(window).ajaxComplete(function() {
    letsJQuery();
});
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .