Telegram - First Message

Navigate to the first message of a Telegram channel by pressing Ctrl+B

  1. // ==UserScript==
  2. // @name Telegram - First Message
  3. // @namespace https://tampermonkey.net/
  4. // @version 0.1
  5. // @description Navigate to the first message of a Telegram channel by pressing Ctrl+B
  6. // @author You
  7. // @match https://t.me/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. const firstMessageUrl = (channelId) => `https://t.me/${channelId}/0`;
  13.  
  14. const navigateToFirstMessage = () => {
  15. const channelLink = document.querySelector('.tgme_channel_info_link');
  16. if (channelLink) {
  17. const channelId = channelLink.getAttribute('href').split('/');
  18. window.location.href = firstMessageUrl(channelId[1]);
  19. }
  20. };
  21.  
  22. const handleKeyPress = (event) => {
  23. if (event.ctrlKey && event.key === 'b') {
  24. navigateToFirstMessage();
  25. }
  26. };
  27.  
  28. document.addEventListener('keypress', handleKeyPress);
  29.  
  30. // Wait for channel info to load (mutation observer)
  31. const observer = new MutationObserver(mutations => {
  32. if (document.querySelector('.tgme_channel_info_link')) {
  33. observer.disconnect();
  34. navigateToFirstMessage();
  35. }
  36. });
  37.  
  38. observer.observe(document.body, { childList: true, subtree: true });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址