Always Open Telegram Link with tp Protocol

convert the URL from "http://t.me" to "tp://"

当前为 2019-03-24 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Always Open Telegram Link with tp Protocol
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  convert the URL from "http://t.me" to "tp://"
// @author       Lee
// @match        https://*/*
// @grant        none
// ==/UserScript==

(function(){
for(var i=0;i<document.links.length;i++){
    var anchor=document.links[i];
    if(anchor.href.match(/^https:\/\/t.me\//)){
        var temp = anchor.href.replace(/^https:\/\/t.me\//, 'tg://resolve?domain=');
        document.links[i].href = temp;
        var method = "_self";
        document.links[i].target = method;
    }

    if(anchor.href.match(/^http:\/\/t.me\//)){
        var temp2 = anchor.href.replace(/^http:\/\/t.me\//, 'tg://resolve?domain=');
        document.links[i].href = temp;
        var method2 = "_self";
        document.links[i].target = method;
    }

    if(anchor.href.match(/^https:\/\/telegram.me\//)){
        var temp3 = anchor.href.replace(/^https:\/\/telegram.me\//, 'tg://resolve?domain=');
        document.links[i].href = temp2;
        var method3 = "_self";
        document.links[i].target = method;
    }

    if(anchor.href.match(/^http:\/\/telegram.me\//)){
        var temp4 = anchor.href.replace(/^http:\/\/telegram.me\//, 'tg://resolve?domain=');
        document.links[i].href = temp;
        var method4 = "_self";
        document.links[i].target = method;
    }
}
})();