diff --git a/README.md b/README.md index 2c683d9..2f0643b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ 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: @@ -25,6 +27,30 @@ Fixing links: + *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 \ No newline at end of file +также исправляются домены telegram.me telegram.dog diff --git a/icons/border-48.png b/icons/icon_48.png similarity index 100% rename from icons/border-48.png rename to icons/icon_48.png diff --git a/manifest.json b/manifest.json index 3b9c0d3..b966e4e 100644 --- a/manifest.json +++ b/manifest.json @@ -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": [ - "" + "", + "webRequest", + "*://t.me/*", + "*://www.t.me/*", + "webRequestBlocking" ], "content_scripts": [ { @@ -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" diff --git a/src/fixer.js b/src/fixer.js index 7f86643..12db125 100644 --- a/src/fixer.js +++ b/src/fixer.js @@ -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; } \ No newline at end of file diff --git a/src/handler_t_me.js b/src/handler_t_me.js new file mode 100644 index 0000000..38b9211 --- /dev/null +++ b/src/handler_t_me.js @@ -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"] +); \ No newline at end of file diff --git a/src/popup/popup.html b/src/popup/popup.html index 57f467c..94cce5b 100644 --- a/src/popup/popup.html +++ b/src/popup/popup.html @@ -7,7 +7,7 @@ - +