Advertisement
Guest User

Untitled

a guest
May 24th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.23 KB | None | 0 0
  1. var ID = function(e) {return document.getElementById(e)};
  2. var t0 = ID("t0"), t1 = ID("t1");
  3. var t0h = ID("t0h"), t1h = ID("t1h");
  4. var timer, timer2;
  5. var old_t0, old_t1;
  6. var map_wd2char =
  7. {
  8. 9999: "!",
  9. 9986: '"',
  10. 9985: "#",
  11. 128083: "$",
  12. 128365: "%",
  13. 128366: "&",
  14. 128367: "'",
  15. 9742: "(",
  16. 9990: ")",
  17. 128386: "*",
  18. 128387: "+",
  19. 128234: ",",
  20. 128235: "-",
  21. 128236: ".",
  22. 128237: "/",
  23. 128193: "0",
  24. 128194: "1",
  25. 128196: "2",
  26. 128463: "3",
  27. 128464: "4",
  28. 128452: "5",
  29. 8987: "6",
  30. 128430: "7",
  31. 128432: "8",
  32. 128434: "9",
  33. 128435: ":",
  34. 128436: ";",
  35. 128427: "<",
  36. 128428: "=",
  37. 9991: ">",
  38. 9997: "?",
  39. 128398: "@",
  40. 9996: "A",
  41. 128076: "B",
  42. 128077: "C",
  43. 128078: "D",
  44. 9756: "E",
  45. 9758: "F",
  46. 9757: "G",
  47. 9759: "H",
  48. 9995: "I",
  49. 9786: "J",
  50. 128528: "K",
  51. 9785: "L",
  52. 128163: "M",
  53. 9760: "N",
  54. 9872: "O",
  55. 127985: "P",
  56. 9992: "Q",
  57. 9788: "R",
  58. 128167: "S",
  59. 10052: "T",
  60. 128326: "U",
  61. 10014: "V",
  62. 128328: "W",
  63. 10016: "X",
  64. 10017: "Y",
  65. 9770: "Z",
  66. 9775: "[",
  67. 2384: "\\",
  68. 9784: "]",
  69. 9800: "^",
  70. 9801: "_",
  71. 9802: "`",
  72. 10048: "{",
  73. 10047: "|",
  74. 10077: "}",
  75. 10078: "~",
  76. 9803: "a",
  77. 9804: "b",
  78. 9805: "c",
  79. 9806: "d",
  80. 9807: "e",
  81. 9808: "f",
  82. 9809: "g",
  83. 9810: "h",
  84. 9811: "i",
  85. 38: "k",
  86. 9679: "l",
  87. 10061: "m",
  88. 9632: "n",
  89. 9633: "o",
  90. 10065: "q",
  91. 10066: "r",
  92. 11047: "s",
  93. 10731: "t",
  94. 9670: "u",
  95. 10070: "v",
  96. 11045: "w",
  97. 8999: "x",
  98. 9043: "y",
  99. 8984: "z",
  100. };
  101. var map_wd2char_ext =
  102. {
  103. 128383: "(",
  104. 128075: "I",
  105. 128073: "F",
  106. 128072: "E",
  107. 128128: "N",
  108. 9723: "o",
  109. 10064: 'r',
  110. 9674: 's',
  111. 9830: 't',
  112. //128316: 'y', // Questionable
  113. 128311: 'u',
  114. 11035: "n",
  115. };
  116. var map_char2wd = {};
  117. for (var p in map_wd2char)
  118. {
  119. if (!map_wd2char.hasOwnProperty(p)) continue;
  120. map_char2wd[map_wd2char[p].charCodeAt(0)] = char2surrogate(p);
  121. //map_char2wd[map_wd2char[p].toLowerCase().charCodeAt(0)] = char2surrogate(p);
  122. }
  123. function char2surrogate(w)
  124. {
  125. if (w >= 0x10000 && w <= 0x10FFFF)
  126. {
  127. var c = String.fromCharCode(Math.floor((w - 0x10000) / 0x400) + 0xD800);
  128. var c2 = String.fromCharCode(((w - 0x10000) % 0x400) + 0xDC00);
  129. return c + c2;
  130. } else {
  131. return String.fromCharCode(w);
  132. }
  133. }
  134. function char2wd(w)
  135. {
  136. return map_char2wd[w] ? map_char2wd[w] : String.fromCharCode(w);
  137. }
  138. function wd2char(w, caps)
  139. {
  140. var r;
  141. if (map_wd2char_ext[w])
  142. {
  143. r = map_wd2char_ext[w];
  144. } else {
  145. r = map_wd2char[w] ? map_wd2char[w] : char2surrogate(w);
  146. }
  147. return caps ? r.toUpperCase() : r;
  148. }
  149. function text2wd(str, caps)
  150. {
  151. var res = [];
  152. if (caps) str = str.toUpperCase();
  153. for (var i = 0; i < str.length; i++)
  154. {
  155. res.push(char2wd(str.charCodeAt(i)));
  156. }
  157. return res.join("");
  158. }
  159. function wd2text(str, caps)
  160. {
  161. var res = [];
  162. for (var i = 0; i < str.length; i++)
  163. {
  164. var c = str.charCodeAt(i);
  165. var u;
  166. if (c >= 0xDC00 && c <= 0xDFFF) continue;
  167. if (c >= 0xD800 && c <= 0xDBFF)
  168. {
  169. var c2 = str.charCodeAt(i + 1);
  170. u = 32;
  171. if (c2 >= 0xDC00 && c2 <= 0xDFFF)
  172. {
  173. u = (c - 0xD800) * 0x400 + c2 + 0x2400;
  174. }
  175. } else {
  176. u = str.charCodeAt(i);
  177. }
  178. res.push(wd2char(u, caps));
  179. }
  180. return res.join("");
  181. }
  182. function upd0()
  183. {
  184. if (old_t0 == t0.value) return;
  185. old_t0 = t0.value;
  186. t1.value = text2wd(t0.value, ID("caps").checked);
  187. t0h.textContent = t0.value;
  188. ID("dbg").innerHTML = parseInt(ID("dbg").innerHTML, 10) + 1;
  189. }
  190. function upd1()
  191. {
  192. if (old_t1 == t1.value) return;
  193. old_t1 = t1.value;
  194. t0.value = wd2text(t1.value, ID("caps").checked);
  195. t1h.textContent = t1.value;
  196. ID("dbg").innerHTML = parseInt(ID("dbg").innerHTML, 10) + 1;
  197. }
  198. function pre_upd0()
  199. {
  200. clearTimeout(timer);
  201. timer = setTimeout(upd0, 100);
  202. }
  203. function pre_upd1()
  204. {
  205. clearTimeout(timer);
  206. timer = setTimeout(upd1, 100);
  207. }
  208. ["change", "keydown", "input"].forEach(function(e)
  209. {
  210. t0.addEventListener(e, pre_upd0);
  211. t1.addEventListener(e, pre_upd1);
  212. });
  213. var skip_sel_event;
  214. function reset_sel_skip()
  215. {
  216. skip_sel_event = false;
  217. }
  218. function sel0()
  219. {
  220. if (t0.selectionStart == t0.selectionEnd)
  221. {
  222. t1h.textContent = t1.value;
  223. } else {
  224. var l = text2wd(t0.value.substring(0, t0.selectionStart)).length;
  225. var n = text2wd(t0.value.substring(t0.selectionStart, t0.selectionEnd)).length;
  226. var part1 = t1.value.substring(0, l).replace(/</g, "&lt;");
  227. var part2 = t1.value.substring(l, l + n).replace(/</g, "&lt;");
  228. var part3 = t1.value.substring(l + n).replace(/</g, "&lt;");
  229. t1h.innerHTML = part1 + "<mark>" + part2 + "</mark>" + part3;
  230. }
  231. scroll1();
  232. setTimeout(reset_sel_skip, 0);
  233. }
  234. function sel1()
  235. {
  236. if (t1.selectionStart == t1.selectionEnd)
  237. {
  238. t0h.textContent = t0.value;
  239. } else {
  240. var l = wd2text(t1.value.substring(0, t1.selectionStart)).length;
  241. var n = wd2text(t1.value.substring(t1.selectionStart, t1.selectionEnd)).length;
  242. var part1 = t0.value.substring(0, l).replace(/</g, "&lt;");
  243. var part2 = t0.value.substring(l, l + n).replace(/</g, "&lt;");
  244. var part3 = t0.value.substring(l + n).replace(/</g, "&lt;");
  245. t0h.innerHTML = part1 + "<mark>" + part2 + "</mark>" + part3;
  246. }
  247. scroll0();
  248. setTimeout(reset_sel_skip, 0);
  249. }
  250. function pre_sel0()
  251. {
  252. if (skip_sel_event) return;
  253. skip_sel_event = true;
  254. clearTimeout(timer2);
  255. timer2 = setTimeout(sel0, 100);
  256. }
  257. function pre_sel1()
  258. {
  259. if (skip_sel_event) return;
  260. skip_sel_event = true;
  261. clearTimeout(timer2);
  262. timer2 = setTimeout(sel1, 100);
  263. }
  264. ["select", "mouseup", "keyup"].forEach(function(e)
  265. {
  266. t0.addEventListener(e, pre_sel0);
  267. t1.addEventListener(e, pre_sel1);
  268. });
  269. function scroll0()
  270. {
  271. t0h.scrollTop = t0.scrollTop;
  272. }
  273. function scroll1()
  274. {
  275. t1h.scrollTop = t1.scrollTop;
  276. }
  277. t0.addEventListener("scroll", scroll0);
  278. t1.addEventListener("scroll", scroll1);
  279. ID("f").addEventListener("click", function(e)
  280. {
  281. var x = e.pageX - this.offsetLeft;
  282. var y = e.pageY - this.offsetTop;
  283. var slot = Math.floor(x / 40) + Math.floor(y / 40) * 16;
  284. var ch = String.fromCharCode(32 + slot);
  285. if (ID("caps").checked) ch = ch.toUpperCase();
  286. t0.value += ch;
  287. t0.scrollTop = 99999;
  288. scroll0();
  289. upd0();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement