Remove Legacy Parameter from Telegram Links

Remove legacy=1 parameter from specific Telegram links

2024/07/20のページです。最新版はこちら

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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);
})();