Telegram to TGStat Link Converter

Convert Telegram links to TGStat links

  1. // ==UserScript==
  2. // @name Telegram to TGStat Link Converter
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Convert Telegram links to TGStat links
  6. // @author w4t3r1ily
  7. // @match *://*/*
  8. // @include *
  9. // @grant none
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=tgstat.com
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Function to create the new Tgstat link element with an arrow sign
  17. function createTgstatLink(username, postId) {
  18. const tgstatLink = document.createElement('a');
  19. tgstatLink.href = `https://tgstat.com/en/channel/@${username}/${postId}`; // Construct the Tgstat URL using the username and post ID
  20. tgstatLink.textContent = `⇒ https://tgstat.com/en/channel/@${username}/${postId}`; // Set the text content of the link with an arrow sign
  21. return tgstatLink; // Return the newly created link element
  22. }
  23.  
  24. // Get all anchor elements on the page
  25. const links = document.querySelectorAll('a');
  26.  
  27. // Iterate over each link
  28. links.forEach(link => {
  29. // Match the URL against the specific Telegram pattern and extract the username and post ID
  30. const match = link.href.match(/https:\/\/t\.me\/([^/]+)\/(\d+)/);
  31. if (match) {
  32. const username = match[1]; // Extract the username from the matched pattern
  33. const postId = match[2]; // Extract the post ID from the matched pattern
  34. const tgstatLink = createTgstatLink(username, postId); // Create a Tgstat link using the extracted username and post ID
  35.  
  36. // Create a line break element
  37. const lineBreak = document.createElement('br');
  38.  
  39. // Insert the line break and then the new link below the original link
  40. link.insertAdjacentElement('afterend', lineBreak); // Insert the line break after the original link
  41. lineBreak.insertAdjacentElement('afterend', tgstatLink); // Insert the new Tgstat link after the line break
  42. }
  43. });
  44. })();

QingJ © 2025

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