Skip to content

Commit

Permalink
bug fixes + new links support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrspartak committed Feb 21, 2020
1 parent 16a5392 commit 51639c8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,23 @@ server {
proxy_http_version 1.1;
}
}
```

## Usage
Can redirect such links:
```
//Profile link
https://t.me/someuser
//Public group
https://t.me/durov
//Group post
https://t.me/durov/112
//Join chat link
https://t.me/joinchat/Br2O30m5d4jsehNIF9kduA
//Add sticker
https://t.me/addstickers/standcat
```
14 changes: 11 additions & 3 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@
var website = document.location.host;
var value = document.getElementById("inputUrl").value;
if(!value) return alert('No link provided');
if(value.indexOf('t.me') == -1) return alert('Wrong link');
value = value.trim().toLocaleLowerCase();
baseValue = value;

if(value.indexOf('t.me') == -1 && value.indexOf('@') == -1) return alert('Wrong link');

var baseScheme = false;
if(value.indexOf('http://') != -1) baseScheme = 'http://';
if(value.indexOf('https://') != -1) baseScheme = 'https://';

var baseScheme = value.indexOf('http://') != -1 ? 'http://' : 'https://';
var currentScheme = document.location.protocol +'//';

var value = value.replace("t.me", website).replace(baseScheme, currentScheme).replace("@", currentScheme + website +"/");
var value = value.replace("t.me", website).replace("@", currentScheme + website +"/");
if(baseScheme) value = value.replace(baseScheme, currentScheme);
else if(baseValue.indexOf('t.me') != -1) value = currentScheme + value;

document.getElementById("inputUrl").value = value;

Expand Down
25 changes: 20 additions & 5 deletions html/redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta charset="UTF-8">
<title>Telegram redirector</title>
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<style type="text/css">%CSS%</style>

</head>
<body>
<div id="outer">
Expand All @@ -32,9 +31,21 @@
var chat = path.replace('/joinchat/', '');
var redirectlink = "tg://" + "join?invite="+ chat;
link.innerHTML = 'Join chat in Telegram';
} else if(path.indexOf('/addstickers/') != -1) {
var stickers = path.replace('/addstickers/', '');
var redirectlink = "tg://" + "addstickers?set="+ stickers;
link.innerHTML = 'Add stickers in Telegram';
} else {
var domain = path.replace('/', '');
var redirectlink = "tg://" + "resolve?domain="+ domain;
var domain = path.replace(/^\//, '');
var isPost = domain.split('/');

if(isPost.length == 2) {
redirectlink = "tg://" + "resolve?domain="+ isPost[0] +'&post='+ isPost[1];
link.innerHTML = 'Open post in Telegram';
} else {
redirectlink = "tg://" + "resolve?domain="+ domain;
link.innerHTML = 'Open in Telegram';
}
}

link.href = redirectlink;
Expand All @@ -47,11 +58,15 @@
timer.innerHTML = "You will be redirected in " + count + " sec.";
setTimeout(counter, 1000);
} else {
window.location.href = redirectlink;
redirect(redirectlink);
timer.innerHTML = "Redirecting...";
}
}

function redirect(url) {
document.location = url;
}

counter();
</script>
</body>
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@

response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
response.setHeader('status', 200);

if (path == '/') {
response.setHeader('Content-Type', 'text/html');
response.setHeader('Content-Type', 'text/html; charset=utf-8');
response.end(indexPage);
} else if (path == '/favicon.ico') {
response.setHeader('Content-Type', 'image/x-icon');
response.end(favicon);
} else {
response.setHeader('Content-Type', 'text/html');
response.setHeader('Content-Type', 'text/html; charset=utf-8');
response.end(redirectPage);
}
});
Expand Down

0 comments on commit 51639c8

Please sign in to comment.