Skip to content

Commit

Permalink
Add redirect t.me, russian description, links bot with params
Browse files Browse the repository at this point in the history
  • Loading branch information
deevroman committed Jun 5, 2020
1 parent 1dca6ce commit a9a0dda
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 10 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,40 @@ For Chrome&Edge soon

**Automatically** changes all links on page *t.me/username* on *tg://resolve?domain=username*

And also in popup allows you to correct the links yourself
Also redirect t.me to you Telegram Client

And in popup allows you to correct the links yourself

Fixing links:

+ *t.me/username*
+ *t.me/channelname/1234*
+ *t.me/joinchat/AAAAAA_1234559*
+ *t.me/addstickers/packname*
+ *t.me/botname?start=XXXX*
+ *t.me/socks?server=ip&port=port&user=user&pass=password*

and telegram.me telegram.dog

## Русское описание

Firefox/Opera**β** расширение для обхода блокировки ссылок t.me

Поддержка Chrome&Edge скоро

**Автоматичсеки** меняет все ссылки *t.me/username* на *tg://resolve?domain=username*

А также перенаправляет t.me в ваш Telegram клиент

В меню расширения вы можете в ручную исправить ссылки

Исправляемые ссылки:

+ *t.me/username*
+ *t.me/channelname/1234*
+ *t.me/joinchat/AAAAAA_1234559*
+ *t.me/addstickers/packname*
+ *t.me/botname?start=XXXX*
+ *t.me/socks?server=ip&port=port&user=user&pass=password*

and telegram.me telegram.dog
также исправляются домены telegram.me telegram.dog
File renamed without changes
17 changes: 13 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{
"manifest_version": 2,
"name": "TgFixer",
"name": "TgFixer (unblock Telegram links)",
"version": "1.0.3",
"description": "__MSG_extensionDescription__",
"author": "Roman Deev",
"homepage_url": "https://github.com/deevroman/TgFixer",
"icons": {
"48": "icons/border-48.png"
"48": "icons/icon_48.png"
},
"permissions": [
"<all_urls>"
"<all_urls>",
"webRequest",
"*://t.me/*",
"*://www.t.me/*",
"webRequestBlocking"
],
"content_scripts": [
{
Expand All @@ -22,10 +26,15 @@
]
}
],
"background": {
"scripts": [
"src/handler_t_me.js"
]
},
"browser_action": {
"default_popup": "src/popup/popup.html",
"default_icon": {
"48": "icons/border-48.png"
"48": "icons/icon_48.png"
}
},
"default_locale": "en"
Expand Down
15 changes: 12 additions & 3 deletions src/fixer.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
function fixUrl(elem){
function fixUrl(elem) {
// usernames
let reg = /^((https:\/\/|http:\/\/)?(telegram\.me|telegram\.dog|t\.me)\/([a-zA-Z0-9_]+))$/g;
if (reg.test(elem.href)) {
elem.href = elem.href.replace(reg, "tg://resolve?domain=$4");
return true;
}
// channel posts
reg = /^((https:\/\/|http:\/\/)?(telegram\.me|telegram\.dog|t\.me)\/([a-zA-Z0-9_]+)\/([0-9]*))$/g;
if (reg.test(elem.href)) {
elem.href = elem.href.replace(reg, "tg://resolve?domain=$4&post=$5");
return true;
}

// bot with params
reg = /^((https:\/\/|http:\/\/)?(telegram\.me|telegram\.dog|t\.me)\/([a-zA-Z0-9_]+)\?start=([a-zA-Z0-9_]*))$/g;
if (reg.test(elem.href)) {
elem.href = elem.href.replace(reg, "tg://resolve?domain=$4&start=$5");
return true;
}
// invite links
reg = /^((https:\/\/|http:\/\/)?(telegram\.me|telegram\.dog|t\.me)\/joinchat\/([a-zA-Z0-9_\-]+))$/g;
if (reg.test(elem.href)) {
elem.href = elem.href.replace(reg, "tg://resolve?invite=$4");
return true;
}

// stickerpacks links
reg = /^((https:\/\/|http:\/\/)?(telegram\.me|telegram\.dog|t\.me)\/addstickers\/([a-zA-Z0-9_]+))$/g;
if (reg.test(elem.href)) {
elem.href = elem.href.replace(reg, "tg://addstickers?set=$4");
return true;
}

return false;
}
31 changes: 31 additions & 0 deletions src/handler_t_me.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
browser.webRequest.onBeforeRequest.addListener(
function (details) {
let url;
const path = details.url.match(/t.me\/(.+)/)[1];
// stickerpacks
if (path.startsWith("addsticker")) {
url = "tg://" + path.replace("/", "?set=");
}
// socks proxy
else if (path.startsWith("socks")) {
url = "tg://" + path;
}
// invite
else if (path.startsWith("joinchat")) {
url = "tg://" + path.replace("joinchat/", "join?invite=");
}
// channel posts and bots with params
else {
url = "tg://resolve?domain=" + path.replace("/", "&post=").replace("?", "&");
}
return {
redirectUrl: url
};
}, {
urls: [
"*://t.me/*",
"*://www.t.me/*",
],
types: ["main_frame", "sub_frame"]
}, ["blocking"]
);
2 changes: 1 addition & 1 deletion src/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>

<body>
<input type="text" class="input-link" id="input-link" placeholder="Type: t.me/username">
<input autofocus type="text" class="input-link" id="input-link" placeholder="Type: t.me/username">
<p id="output-link"></p>
<script src="../fixer.js"></script>
<script src="popup.js"></script>
Expand Down

0 comments on commit a9a0dda

Please sign in to comment.