Greasy Fork is available in English.

Telegram Link Converter

Rewrite t.me links to tgstat.com links

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         Telegram Link Converter
// @version      1.0
// @description  Rewrite t.me links to tgstat.com links
// @author       w4t3r1ily
// @match        *://*/*
// @grant        none
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tgstat.com
// @namespace https://greasyfork.org/users/905173
// ==/UserScript==

(function() {
    'use strict';

    var links = document.getElementsByTagName('a');

    for (var i = 0; i < links.length; i++) {
        var link = links[i];
        var href = link.href;
        if (href.includes('t.me')) {
            var parts = href.split('/');
            var username = parts[parts.length - 2];
            var postID = parts[parts.length - 1];
            var newLink = document.createElement('a');
            newLink.href = 'https://tgstat.com/en/channel/@' + username + '/' + postID;
            newLink.textContent = '' + newLink.href;
            var br = document.createElement('br');
            link.parentNode.insertBefore(br, link.nextSibling);
            link.parentNode.insertBefore(newLink, br.nextSibling);
        }
    }
})();