Telegram markup extension

presented below

  1. // ==UserScript==
  2. // @name Telegram markup extension
  3. // @namespace https://gist.github.com/W-1/
  4. // @version 0.2
  5. // @description presented below
  6. // @author W-1
  7. // @match *://web.telegram.org/
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /*
  12. *
  13. * [_text_] => t̲e̲x̲t̲
  14. * [-text-] => ̶t̶e̶x̶t̶
  15. * [_[-text-]_] => ̶̶̲t̶̶̲e̶̶̲x̶̶̲t̶̲
  16. * [^text^] => ᴛᴇxᴛ
  17. * [@text@] => ????
  18. * [|text|] => ????
  19. * [$text$] => ????
  20. * [=text=] => ????
  21. * [%text%] => text
  22. *
  23. */
  24.  
  25. document.querySelector('.composer_rich_textarea').onkeydown = e => {
  26. if(e.keyCode!==13)
  27. return;
  28. const abc = ['abcdefghijklmnopqrstuvwxyz'],
  29. abcI = e => abc.join('').indexOf(e),
  30. mapjoin = (s,f) => [...s].map(l=>f(l,abcI(l))).join('');
  31. abc.push(abc[0].toUpperCase());
  32.  
  33. const cmd = [
  34. ['_','̲'],
  35. ['-','̶'],
  36. ['^','ᴀʙᴄᴅᴇғɢʜɪᴊᴋʟᴍɴᴏᴘǫʀsᴛᴜᴠᴡxʏᴢ'],
  37. ['@','??????????????????????????'],
  38. ['|','????????????????????????????ℂ????ℍ?????ℕ?ℙℚℝ???????ℤ'],
  39. ['$','????????????????????????????????????????????????????'],
  40. ['=','????????????????????????????????????????????????????'],
  41. ['%','abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ']
  42. ];
  43. let text = e.target.innerText;
  44. for (let [r,s] of cmd){
  45. if(!(new RegExp(`\\[\\${r}.*\\${r}\\]`).test(text)))
  46. continue;
  47. let t = text.split(new RegExp(`\\[\\${r}|\\${r}\\]`));
  48. text = t[0];
  49. switch(r){
  50. case '^': text += mapjoin(t[1], (l,i) => i!==-1&&i<26?s[i]:l);
  51. break;
  52. case '@': text += mapjoin(t[1], (l,i) => i!==-1?[...s][i<26?i:i-26]:l);
  53. break;
  54. case '-':
  55. case '_': text += mapjoin(t[1], l => ['[',']',...cmd.map(c=>c[0])].indexOf(l)!==-1?l:s+l)+s;
  56. break;
  57. default: text += mapjoin(t[1], (l,i) => i!==-1?[...s][i]:l);
  58. }
  59. text += t[2];
  60. }
  61. e.target.innerText=text;
  62. return true;
  63. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址