Telegram markup extension

presented below

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         Telegram markup extension
// @namespace    https://gist.github.com/W-1/
// @version      0.2
// @description  presented below
// @author       W-1
// @match        *://web.telegram.org/
// @grant        none
// ==/UserScript==

/*
*
*    [_text_]   => t̲e̲x̲t̲
*    [-text-]   => ̶t̶e̶x̶t̶
*  [_[-text-]_] => ̶̶̲t̶̶̲e̶̶̲x̶̶̲t̶̲
*    [^text^]   => ᴛᴇxᴛ
*    [@text@]   => ????
*    [|text|]   => ????
*    [$text$]   => ????
*    [=text=]   => ????
*    [%text%]   => text
*
*/

document.querySelector('.composer_rich_textarea').onkeydown = e => {
  if(e.keyCode!==13)
    return;
  
  const abc = ['abcdefghijklmnopqrstuvwxyz'],
        abcI = e => abc.join('').indexOf(e),
        mapjoin = (s,f) => [...s].map(l=>f(l,abcI(l))).join('');
  abc.push(abc[0].toUpperCase());

  const cmd = [
    ['_','̲'],
    ['-','̶'],
    ['^','ᴀʙᴄᴅᴇғɢʜɪᴊᴋʟᴍɴᴏᴘǫʀsᴛᴜᴠᴡxʏᴢ'],
    ['@','??????????????????????????'],
    ['|','????????????????????????????ℂ????ℍ?????ℕ?ℙℚℝ???????ℤ'],
    ['$','????????????????????????????????????????????????????'],
    ['=','????????????????????????????????????????????????????'],
    ['%','abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ']
  ];
  
  let text = e.target.innerText;
  
  for (let [r,s] of cmd){
    if(!(new RegExp(`\\[\\${r}.*\\${r}\\]`).test(text)))
      continue;
    
    let t = text.split(new RegExp(`\\[\\${r}|\\${r}\\]`));
    
    text = t[0];
    
    switch(r){
      case '^': text += mapjoin(t[1], (l,i) => i!==-1&&i<26?s[i]:l);
        break;
      case '@': text += mapjoin(t[1], (l,i) => i!==-1?[...s][i<26?i:i-26]:l);
        break;
      case '-':
      case '_': text += mapjoin(t[1], l => ['[',']',...cmd.map(c=>c[0])].indexOf(l)!==-1?l:s+l)+s;
        break;
      default: text += mapjoin(t[1], (l,i) => i!==-1?[...s][i]:l);
    }
    
    text += t[2];
  }
  
  e.target.innerText=text;
  return true;
}