Remove Legacy Parameter from Telegram Links

Remove legacy=1 parameter from specific Telegram links

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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);
})();