Replace blocked Telegram links

After blocking Telegram in Russia, links to stopped working:

Error when trying to access

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 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'

Change the link if the site is blocked:

isBlocked('').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.