t.me Open in Web Telegram K for Firefox

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

目前為 2025-03-28 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         t.me Open in Web Telegram K for Firefox
// @namespace    http://tampermonkey.net/
// @version      2025-03-28
// @description  This script allows you to open t.me links in Web Telegram K in Firefox
// @author       You
// @match        https://t.me/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=t.me
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    /* Function to get channel ID */
    function getChannelId(url) {
        return url.replace(/^https:\/\/t\.me\//, "");
    }
    /* Get the current location */
    const currentUrl = window.location.href;
    /* Get channel ID from the current location */
    const channelId = getChannelId(currentUrl);
    /* Find the button that takes you to the desktop client */
    const desktopClient = document.querySelector('.tgme_page_action');
    /* Add a new button below to go to the web client */
    if (desktopClient) {
        const webClient = document.createElement('div');
        webClient.classList.add('tgme_page_action', 'tgme_page_web_action');
        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>`;
        desktopClient.insertAdjacentElement('afterend', webClient);
    }
    /* Hide channel preview link in t.me */
    const previewLink = document.querySelector('.tgme_page_context_link_wrap');
    previewLink.style.display = 'none';
})();