-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add redirect t.me, russian description, links bot with params
- Loading branch information
Showing
6 changed files
with
85 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters