Telegram markup extension

presented below

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

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

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

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

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

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

// ==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;
}