External domain link blocklist

Is there a way to prevent a specific domain from being linked at all?

The use-case is the following: a user keeps responding to any topic with links to their website, which is not necessarily bad nor dangerous, but the result is that all conversations feel hijacked and spammy. After insisting several times with this user, the posting pattern persists. Note that the rel="nofollow" does not seem to prevent such behavior.

I’m thinking that removing the links entirely, or even preventing posting when the domain appears may give an incentive to contribute to the conversation itself for its own sake rather than to spit out external links all the time.

Maybe there are other, non-technical ways to address this issue, but I can see it as a potentially recurring issue across forums.

1 Like

A quick solution may be to downgrade the user so that he cannot post any links at all.

2 Likes

You could put the link itself on the /admin/customize/watched_words/action/block list.

7 Likes

@Firepup650’s watched words suggestion is useful when a variety of people are posting links to a small number of spammy sites. Definitely a useful tool to have. In this case it seems like you have a user who is pushing the limits of what’s socially acceptable. You might want to consider a self-promotion policy as well. That might solve the problem without bringing in the block, which might feel heavy-handed.

An inevitable problem with blocklists is that persistent offenders find ways around it. A well-formed policy can create a community norm that channels users into more productive activity. And if not, blocking still remains a potential solution. :wink:

2 Likes

Indeed either block the domain in watched words or even have a bit of minor fun. And have it replace the url with something like “Oops NoGo”

I had the same question also for short domain names e.g. if you want to block “ent.com” you also need to avoid it blocking “content.com”.

Having ent.com as a watched word doesn’t get triggered with content.com. Or do I misunderstand you?
Also you can use regular expressions to fine tune watched words for URLs you don’t want see posted.

2 Likes

thanks so if you put “ent.com” would it block all variations of “http(s)://ent.com/[url]?” where url is an arbitrary sequence?

OK. I think I need to use regexp

2 Likes

Thank you for your replies. I remember having tried various ways of watched words but links do not get unlinked AFAIK. Can someone provide a working example?

1 Like

A very basic theme component (courtesy of :robot:) using a hardcoded domain list:

<script type="text/discourse-plugin" version="0.8.25">
  api.decorateCookedElement((element) => {

    const domainsToUnlink = ["example.com", "specificdomain.com"];

    const links = element.querySelectorAll("a");

    links.forEach((link) => {
      const url = new URL(link.href);
      if (domainsToUnlink.includes(url.hostname)) {
        const textNode = document.createTextNode(link.textContent);
        link.replaceWith(textNode);
      }
    });
  }, { id: "unlink-specific-domains" });
</script>

2 Likes

Just to get my brain on this.

The script converts a specified link to unclicksble plain text version of link?

Could it be modified to replace link say with “Forbidden” maybe as a link to a rules post with a list of not allowed domains?

1 Like

Yes for both questions :slight_smile:

1 Like