Always Open Telegram Link with tp Protocol

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

  1. // ==UserScript==
  2. // @name Always Open Telegram Link with tp Protocol
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description convert the URL from "http://t.me" or "http://telegram.me" to "tp://"
  6. // @author Lee
  7. // @match https://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function(){
  12. for(var i=0;i<document.links.length;i++){
  13. var anchor=document.links[i];
  14. if(anchor.href.match(/^\S*:\/\/t.me\//) || anchor.href.match(/^\S*:\/\/telegram.me\//)){
  15. var temp = anchor.href.replace(/^\S*.me\//, 'tg://resolve?domain=');
  16. document.links[i].href = temp;
  17. var method = "_self";
  18. document.links[i].target = method;
  19. }
  20. }
  21. })();