Skip to content

Instantly share code, notes, and snippets.

@0xdevalias
Last active May 11, 2024 01:47
Show Gist options
  • Save 0xdevalias/8885b10795eb3267b703ed5943087953 to your computer and use it in GitHub Desktop.
Save 0xdevalias/8885b10795eb3267b703ed5943087953 to your computer and use it in GitHub Desktop.
Notes on API/userscript to improve Twitter 'Notifications Timeline'

Notes on API/userscript to improve Twitter 'Notifications Timeline'

Table of Contents

Tools/Libraries/Etc

Unsorted

On Twitter, from my notifications page:

When I click on the 'New post notifications for...' section, I am taken to a new page:

As part of this page, an API call is made to fetch the tweets to be shown:

This returns JSON data, from which we can extract the Tweets, and sort them by post time with something like jq:

pbpaste | jq '.globalObjects.tweets | to_entries | sort_by(.value.created_at | strptime("%a %b %d %H:%M:%S %z %Y")) | reverse | from_entries' | subl

This data will then look something like this:

{
  "1734010714510049396": {
    "created_at": "Mon Dec 11 00:42:25 +0000 2023",
    "id": 1734010714510049300,
    "id_str": "1734010714510049396",
    "full_text": "Don’t be S-A-D! https://t.co/fkHsvfwuGG",
    "truncated": false,
    "display_text_range": [
      0,
      15
    ],
    "entities": { /* ..snip.. */ },
    "extended_entities": { /* ..snip.. */ },
    "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
    "in_reply_to_status_id": null,
    "in_reply_to_status_id_str": null,
    "in_reply_to_user_id": null,
    "in_reply_to_user_id_str": null,
    "in_reply_to_screen_name": null,
    "user_id": 44196397,
    "user_id_str": "44196397",
    "geo": null,
    "coordinates": null,
    "place": null,
    "contributors": null,
    "is_quote_status": false,
    "retweet_count": 5203,
    "favorite_count": 56940,
    "reply_count": 3883,
    "quote_count": 410,
    "conversation_id": 1734010714510049300,
    "conversation_id_str": "1734010714510049396",
    "conversation_muted": false,
    "favorited": false,
    "retweeted": false,
    "possibly_sensitive": false,
    "lang": "en",
    "ext": {
      "superFollowMetadata": {
        "r": {
          "ok": {}
        },
        "ttl": -1
      }
    }
  },
  // ..snip..
}

From that info (and matching against the DOM itself), it should be possible to implement a userscript/similar that can:

  • mark where the last tweet I saw was (both automatically, and manually)
  • hide/dim tweets older than that
  • tell me how many tweets there are till I am 'caught up'
  • etc

See Also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment