Remove Legacy Parameter from Telegram Links

Remove legacy=1 parameter from specific Telegram links

Version vom 20.07.2024. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Remove Legacy Parameter from Telegram Links
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Remove legacy=1 parameter from specific Telegram links
// @author       Your Name
// @match        https://t.me/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to remove legacy=1 from a URL
    function removeLegacyParameter(url) {
        let urlObj = new URL(url);
        urlObj.searchParams.delete('legacy');
        return urlObj.toString();
    }

    // Function to update all links on the page
    function updateLinks() {
        // Get all links on the page
        let links = document.querySelectorAll('a');

        // Remove legacy=1 from each link
        links.forEach(link => {
            if (link.href.includes('legacy=1')) {
                link.href = removeLegacyParameter(link.href);
                console.log('Removed legacy=1 from ' + link.href);
            }
        });
    }

    // Run updateLinks when the page is loaded
    window.addEventListener('load', updateLinks);

    // Run updateLinks every second to handle dynamic content
    setInterval(updateLinks, 1000);
})();