As for millions of users, Telegram is part of my communication toolkit: family, friends, community and some pet projects are connected through this fascinating chat system.

When it comes to desktop experience, Telegram offers a couple of options: native app or web app. I’m not a big fan of native apps: things like Slack sucking RAM like-there-is-no-tomorrow kinda traumatized me. I usually prefer the web interface that is available at https://web.telegram.org/

The missing shortcut

I have been using Slack since forever and one of the most used shortcuts, for me, is Cmd+K to quickly navigate to the next unread message (I guess is Ctrl+K on Windows, but I’m not sure. Let me know in the comments).

I couldn’t find something similar for Telegram and I really missed it. I kept hitting Cmd+K while using Telegram, the same way I keep trying to use IntelliJ shortcuts whenever I have a text editor: muscle memory is a tricky thing.

The solution

In one of my previous posts, Enable Push-to-talk in Google Meet, I introduced you to Tampermonkey, a handy way to add userscripts to your browser.

I’m very fond of userscripts and I decided to give it a shot with Telegram. It took me almost one hour of hacking around with JS, DOM, jQuery & Co. but eventually I got it working:

// ==UserScript==
// @name         Telegram - Jump to first unread message
// @namespace    https://ivanmorgillo.com/
// @version      0.1
// @description  Kinda Slack shortcut
// @author       Ivan Morgillo
// @match        https://web.telegram.org/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
window.$(document).on("keydown", function(e){
    if (e.keyCode == 75 && (e.ctrlKey || e.metaKey)){
        var unread = window.$( '.im_dialog_badge.badge:not(".ng-hide")' ).first();

        if (unread != undefined) {
            var container = unread.parent().parent();
            container.mousedown();
            console.log("container clicked");
        }
    }
});
})();

You can keep an eye on the gist here.

This is the first super-duper-proof-of-concept-works-so-far version. Please give it a shot and let me know if it works for you, especially if you are a Windows/Linux user 😃👍🏻