Advertisement
jcunews

convert-and-redirect-t.me-to-telegram.me.user.js

Sep 15th, 2022
1,377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Convert and redirect t.me to telegram.me
  3. // @namespace    https://greasyfork.org/en/users/85671-jcunews
  4. // @version      1.0.1
  5. // @license      AGPL v3
  6. // @author       jcunews
  7. // @description  Context: https://www.reddit.com/r/userscripts/comments/xey0b1/request_userscript_which_redirects_tme_to/
  8. // @match        *://*/*
  9. // @grant        none
  10. // @run-at       document-start
  11. // ==/UserScript==
  12.  
  13. (() => {
  14.   if ((location.hostname === "t.me") && !sessionStorage.tmeRedired) {
  15.     sessionStorage.tmeRedired = 1;
  16.     return location.hostname = "telegram.me"
  17.   }
  18.   function chkEle(e) {
  19.     if ((e.tagName === "A") && (e.hostname === "t.me")) {
  20.       e.hostname = "telegram.me"
  21.     } else e.querySelectorAll && e.querySelectorAll('a').forEach(chkEle)
  22.   }
  23.   (new MutationObserver(recs => {
  24.     recs.forEach(rec => rec.addedNodes.forEach(chkEle))
  25.   })).observe(document, {childList: true, subtree: true})
  26. })();
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement