Unsubscribing from Reddit Community Notifications

Reddit has been recently ramping up their "Popular post in" and other community notifications. I find these all incredibly low value, and want to turn them off. 1 And so do others.

You can go to an individual subreddit and turn them off for that subreddit. But as far as I can tell, there's no way to turn them off everywhere—just individually per subreddit.

If you go to https://www.reddit.com/settings/notifications there's a "Community notifications" option that allows you to see all your subreddits and set the setting directly, but it doesn't paginate 2 This is likely a bug, but also one that Reddit isn't incentivized to fix. and only shows the top 25 alphabetical subreddits that you're subscribed to:

But Reddit uses GraphQL! So let's use some request replaying to turn them all off at once.

Getting the GraphQL request

The general approach will be to copy the request that turns the notifications off for one subreddit, and then run it across all the subreddits you're subscribed to. First we need the individual request. Open the Developer Tools (Cmd ⌘+Option ⌥+I on Mac) and go to Network. Then change one of the settings to "Off" (I did /r/CozyPlaces). This should create a graphql row.

Right-click and go to "Copy" > "Copy as fetch".

This will give you some JS code like this which can be used to replay the request.

fetch("https://www.reddit.com/svc/shreddit/graphql", {
  "headers": {
    "accept": "application/json",
    "accept-language": "en-US,en;q=0.9",
    "baggage": /* anonymized */,
    "cache-control": "no-cache",
    "content-type": "application/json",
    "pragma": "no-cache",
    "priority": "u=1, i",
    "sec-ch-ua": "\"Chromium\";v=\"134\", \"Not:A-Brand\";v=\"24\", \"Google Chrome\";v=\"134\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"macOS\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "sentry-trace": /* anonymized */
  },
  "referrer": "https://www.reddit.com/settings/notifications",
  "referrerPolicy": "strict-origin-when-cross-origin",
  "body": "{\"operation\":\"UpdateSubredditMuteAndNotificationLevelSettings\",\"variables\":{\"input\":{\"subredditId\":\"t5_34ixl\",\"isUpdateFromSubredditEnabled\":false,\"isSubredditUpdatesInterestingPostEnabled\":false}},\"csrf_token\":\"<anonymized>\"}",
  "method": "POST",
  "mode": "cors",
  "credentials": "include"
});

The main portion is the body line, which specifies the GraphQL method (UpdateSubredditMuteAndNotificationLevelSettings) and the variables that it's passing up.

{
  "operation": "UpdateSubredditMuteAndNotificationLevelSettings",
  "variables": {
    "input": {
      "subredditId": "t5_34ixl",
      "isUpdateFromSubredditEnabled": false,
      "isSubredditUpdatesInterestingPostEnabled": false
    }
  },
  "csrf_token": "<anonymized>"
}

We want to tweak the subredditId, which in this case is t5_34ixl. You can find this by going to about.json for a given subreddit (https://www.reddit.com/r/CozyPlaces/about.json for /r/CozyPlaces) and finding the field "name":

Getting all of the subreddit IDs

To turn these off en masse we need all of the IDs. There's good ways to do this with the formal Reddit API but we're looking for something quick and dirty that you can do in browser. If you go to https://reddit.com/subreddits/mine it will have a list of all of the subreddits you're currently subscribed to (by name). On the right side there's a full list of your subscriptions, each with a button.

Each of those has onclick code with the hardcoded ID. We can extract them all with one line 3 Functional programming! Abusing the definition of "one line" since 1937! of JavaScript!

var subredditIDs = [...document.querySelectorAll('a.option.active.remove[onclick*="unsubscribe"]')]
  .map(a => a.getAttribute('onclick').match(/unsubscribe\('([^']+)'\)/)?.[1])
  .filter(Boolean);

Putting it all together

The last piece that we need to create a script that will work for anyone is one of those anonymized fields. Without the csrf_token the request will fail, which is luckily stored in your cookies—we can add querying it to the top of the script. Just navigate to https://www.reddit.com/subreddits/mine and copy and paste the following in your Chrome 4 Fine, or Safari or Firefox or Opera or Brave or Arc, you nerd. Unless you've disabled JavaScript, in which case let's be honest, you've turned off all Reddit notifications anyways. console: 5 In general you shouldn't evaluate random JavaScript that a blog gives you, but hopefully combined with the post the script is followable enough to sanity check that it's doing what I say it does.

var subredditIDs = [...document.querySelectorAll('a.option.active.remove[onclick*="unsubscribe"]')]
  .map(a => a.getAttribute('onclick').match(/unsubscribe\('([^']+)'\)/)?.[1])
  .filter(Boolean);

var csrf_token = document.cookie.split('; ').find(row => row.startsWith('csrf_token='))?.split('=')[1];

for (const id of subredditIDs) {
  fetch("https://www.reddit.com/svc/shreddit/graphql", {
    "headers": {
      "accept": "application/json",
      "accept-language": "en-US,en;q=0.9",
      "cache-control": "no-cache",
      "content-type": "application/json",
      "pragma": "no-cache",
      "priority": "u=1, i",
      "sec-ch-ua": "\"Chromium\";v=\"134\", \"Not:A-Brand\";v=\"24\", \"Google Chrome\";v=\"134\"",
      "sec-ch-ua-mobile": "?0",
      "sec-ch-ua-platform": "\"macOS\"",
      "sec-fetch-dest": "empty",
      "sec-fetch-mode": "cors",
      "sec-fetch-site": "same-origin"
    },
    "referrer": "https://www.reddit.com/settings/notifications",
    "referrerPolicy": "strict-origin-when-cross-origin",
    "body": JSON.stringify({
        operation: "UpdateSubredditMuteAndNotificationLevelSettings",
        variables: {
          input: {
            subredditId: id,
            isUpdateFromSubredditEnabled: false,
            isSubredditUpdatesInterestingPostEnabled: false
          }
        },
        csrf_token: csrf_token
    }),
    "method": "POST",
    "mode": "cors",
    "credentials": "include"
  });
}

Finally all we can do is send off a prayer that Reddit fixes their pagination soon and offers a full "off" option for community notifications.


  1. And so do others↩︎

  2. This is likely a bug, but also one that Reddit isn't incentivized to fix. ↩︎

  3. Functional programming! Abusing the definition of "one line" since 1937! ↩︎

  4. Fine, or Safari or Firefox or Opera or Brave or Arc, you nerd. Unless you've disabled JavaScript, in which case let's be honest, you've turned off all Reddit notifications anyways. ↩︎

  5. In general you shouldn't evaluate random JavaScript that a blog gives you, but hopefully combined with the post the script is followable enough to sanity check that it's doing what I say it does. ↩︎