After blocking Telegram in Russia, links to t.me stopped working:
But the Telegram has its own protocol, which is supported by official applications and is not blocked. This is what the link to open a dialog with me looks like: tg://resolve?domain=alik0211. You need to give a link to users who have a site t.me blocked.
To check the site for blocking you need to send an ajax request using fetch
. We will get the following function:
function isBlocked(url) {
return new Promise((resolve, reject) => {
fetch(url, {
mode: 'no-cors'
})
.then(reject)
.catch(resolve);
});
}
Change the link if the site is blocked:
isBlocked('https://t.me').then(() => {
const linkElement = document.getElementById('tg-link');
linkElement.href = 'tg://resolve?domain=alik0211';
});
This script is published in npm and its source code is available on github.