Remove Legacy Parameter from Telegram Links

Remove legacy=1 parameter from specific Telegram links

  1. // ==UserScript==
  2. // @name Remove Legacy Parameter from Telegram Links
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Remove legacy=1 parameter from specific Telegram links
  6. // @author Your Name
  7. // @match https://t.me/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to remove legacy=1 from a URL
  16. function removeLegacyParameter(url) {
  17. let urlObj = new URL(url);
  18. urlObj.searchParams.delete('legacy');
  19. return urlObj.toString();
  20. }
  21.  
  22. // Function to update all links on the page
  23. function updateLinks() {
  24. // Get all links on the page
  25. let links = document.querySelectorAll('a');
  26.  
  27. // Remove legacy=1 from each link
  28. links.forEach(link => {
  29. if (link.href.includes('legacy=1')) {
  30. link.href = removeLegacyParameter(link.href);
  31. console.log('Removed legacy=1 from ' + link.href);
  32. }
  33. });
  34. }
  35.  
  36. // Run updateLinks when the page is loaded
  37. window.addEventListener('load', updateLinks);
  38.  
  39. // Run updateLinks every second to handle dynamic content
  40. setInterval(updateLinks, 1000);
  41. })();