t.me Open in Web Telegram K for Firefox

This script allows you to open t.me links in Web Telegram K in Firefox

  1. // ==UserScript==
  2. // @name t.me Open in Web Telegram K for Firefox
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description This script allows you to open t.me links in Web Telegram K in Firefox
  6. // @author jugami1
  7. // @match https://t.me/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=t.me
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. /* Function to get channel ID */
  17. function getChannelId(url) {
  18. return url.replace(/^https:\/\/t\.me\//, "");
  19. }
  20. /* Get the current location */
  21. const currentUrl = window.location.href;
  22. /* Get channel ID from the current location */
  23. const channelId = getChannelId(currentUrl);
  24. /* Find the button that takes you to the desktop client */
  25. const desktopClient = document.querySelector('.tgme_page_action');
  26. /* Add a new button below to go to the web client */
  27. if (desktopClient) {
  28. const webClient = document.createElement('div');
  29. webClient.classList.add('tgme_page_action', 'tgme_page_web_action');
  30. webClient.innerHTML = `<a class="tgme_action_button_new tgme_action_web_button" href="https://web.telegram.org/k/#?tgaddr=tg%3A%2F%2Fresolve%3Fdomain%3D${channelId}"><span class="tgme_action_button_label">Open in Web</span></a>`;
  31. desktopClient.insertAdjacentElement('afterend', webClient);
  32. }
  33. /* Hide channel preview link in t.me */
  34. const previewLink = document.querySelector('.tgme_page_context_link_wrap');
  35. previewLink.style.display = 'none';
  36. })();