Wrong Chat

Just chat to chat with nearby players

  1. // ==UserScript==
  2. // @name Wrong Chat
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3.13
  5. // @description Just chat to chat with nearby players
  6. // @author unnamed
  7. // @match https://splix.io/
  8. // @match https://splix.io/flags
  9. // @grant none
  10. // @run-at document-start
  11. // @require https://update.greasyfork.org/scripts/478491/1377223/splix-js-demodularizer.js
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. "use strict";
  16.  
  17. var source = `"use strict";
  18.  
  19. var wcFlags = {};
  20. var wcFlagList = [
  21. {
  22. "name": "wcConvertEmoticons",
  23. "caption": "Convert emoticons in your messages to emoji",
  24. "description": ":D ⟶ 😄",
  25. "type": "checkbox",
  26. "default": true
  27. },
  28. {
  29. "name": "wcConsoleLog",
  30. "caption": "Print messages to the browser console",
  31. "description": "Until the page is refreshed, you can see the message history in the console.",
  32. "type": "checkbox",
  33. "default": true
  34. },
  35. {
  36. "name": "wcConsoleLogTimeAmPm",
  37. "caption": "Use AM/PM time format for console log",
  38. "description": "Uncheck if you want to use 24 hour format",
  39. "type": "checkbox",
  40. "default": true
  41. },
  42. {
  43. "name": "wcMsgDisplayTime",
  44. "caption": "Message display time",
  45. "description": "The total display time (seconds) of the message.<br>If this value is zero, messages will only be deleted when the message limit is reached.",
  46. "type": "number",
  47. "default": 90,
  48. "min": 0,
  49. "max": 3600
  50. },
  51. {
  52. "name": "wcMsgDecayTime",
  53. "caption": "Message decay time",
  54. "description": "The time (seconds) during which the messages fade out.<br>It is part of the total display time.",
  55. "type": "number",
  56. "default": 20,
  57. "min": 0,
  58. "max": 3600
  59. },
  60. {
  61. "name": "wcMessageLimit",
  62. "caption": "Number of messages on screen",
  63. "description": "Maximum number of messages displayed on the screen.",
  64. "type": "number",
  65. "default": 20,
  66. "min": 0,
  67. "max": 50
  68. },
  69. {
  70. "name": "wcDefaultNotifications",
  71. "caption": "Show default notifications",
  72. "description": "Show default splix.io notifications instead of bottom right corner notifications.<br>This parameter only affects the notifications shown by the Wrong Chat script.",
  73. "type": "checkbox",
  74. "default": false
  75. },
  76. {
  77. "name": "wcPrivacyWarnings",
  78. "caption": "Enable privacy warnings",
  79. "description": "Disable this flag if you understand the risks of communicating in this chat.<br>Even if you don't see anyone nearby, someone can see your messages.<br>Also, do not disclose important information as the interlocutor may impersonate someone else.",
  80. "type": "checkbox",
  81. "default": true
  82. },
  83. {
  84. "name": "wcBlockedPlayers",
  85. "caption": "Blocked players",
  86. "description": "List of blocked players in JSON format.<br>Clear the field if you want to clear the list.",
  87. "type": "text",
  88. "default": {}
  89. },
  90. ];
  91.  
  92. (function wcGetFlags() {
  93. for (var i = 0; i < wcFlagList.length; i++) {
  94. var value = localStorage.getItem(wcFlagList[i].name);
  95. if (value !== null) {
  96. if (wcFlagList[i].type == "number") {
  97. value = Number.parseInt(value);
  98. if (Number.isNaN(value)) {
  99. value = wcFlagList[i].default;
  100. }
  101. }
  102. else if (wcFlagList[i].type == "checkbox") {
  103. value = (value == "true");
  104. }
  105. else if (wcFlagList[i].type == "text" && wcFlagList[i].name == "wcBlockedPlayers") {
  106. wcLoadBlockedPlayers();
  107. continue;
  108. }
  109. }
  110. else {
  111. value = wcFlagList[i].default;
  112. }
  113. wcFlags[wcFlagList[i].name] = value;
  114. }
  115. }());
  116.  
  117. if (window.location.pathname == "/flags") {
  118. (function wcFlagListAddControls() {
  119. addHTML('<h4 style="margin-top: 1.5em; margin-bottom: 1em">Wrong Chat Flags</h4>', 'body');
  120. for (var i = 0; i < wcFlagList.length; i++) {
  121. var flag = wcFlagList[i];
  122. var control = \`<label>\${flag.caption}\\t\${flag.name == "wcBlockedPlayers" ? "<br><textarea" : "<input"} name="\${flag.name}" type="\${flag.type}" \${(flag.type == "number") ?
  123. (' style="width: 50px"' + (('min' in flag) ? ' min="' + flag.min + '"' : " ") + (('max' in flag) ? ' max="' + flag.max + '"' : " ") + ' value="' + wcFlags[flag.name] + '"') :
  124. (flag.type == "text" ? (' style="width: 600px; height: 50px"') :
  125. ((flag.type == "checkbox" && wcFlags[flag.name]) ? " checked" : ""))}>\${flag.name == "wcBlockedPlayers" ? "</textarea>" : ""}</label>
  126. <div class="st">\${flag.description}</div>\`;
  127.  
  128. addHTML(control, "body");
  129.  
  130. if (flag.name == "wcBlockedPlayers") {
  131. document.querySelector('textarea[name="wcBlockedPlayers"]').value = JSON.stringify(wcFlags[flag.name]);
  132. }
  133.  
  134. document.querySelector("label:last-of-type input, label:last-of-type textarea").addEventListener("change", function (e) {
  135. if (e.target.type == "number") {
  136. if (!Number.isNaN(e.target.valueAsNumber)) {
  137. localStorage.setItem(e.target.name, e.target.value);
  138. wcFlags[e.target.name] = e.target.valueAsNumber;
  139. }
  140. }
  141. else if (e.target.type == "checkbox") {
  142. localStorage.setItem(e.target.name, e.target.checked);
  143. wcFlags[e.target.name] = e.target.checked;
  144. }
  145. else if (e.target.tagName == "TEXTAREA") {
  146. try {
  147. if (e.target.value.trim() === "") {
  148. localStorage.setItem("wcBlockedPlayers", "{}");
  149. }
  150. else {
  151. var obj = JSON.parse(e.target.value);
  152. localStorage.setItem("wcBlockedPlayers", JSON.stringify(obj));
  153. }
  154. wcLoadBlockedPlayers(false);
  155. }
  156. catch { }
  157. }
  158. });
  159. }
  160. }());
  161. throw new Error("Nobody will read the text of this error"); /** Stop code execution from here */
  162. }
  163.  
  164. var dict = ["especially", "understand", "everything", "themselves", "associated", "experience", "something", "sometimes", "different", "necessary", "important", "condition", "operation", "direction", "attention", "therefore", "character", "situation", "according", "questions", "described", "territory", "establish", "https://", "immortal", "parasite", "anything", "actually", "happened", "national", "question", "possible", "although", "probably", "business", "pressure", "together", "couldn't", "remember", "southern", "frequent", "interest", "children", "everyone", "continue", "whatever", "position", "features", "wouldn't", "movement", "declared", "complete", "presence", "consider", "appeared", "industry", "thousand", "thinking", "language", "majority", "consists", "distance", "involved", "yourself", "entirely", "increase", "standing", "property", "surround", "private", "browser", "careful", "connect", "discord", "http://", "latency", "message", "players", "protect", "refresh", "restart", "running", "through", "because", "against", "thought", "without", "between", "nothing", "another", "usually", "however", "country", "himself", "patient", "certain", "general", "brother", "already", "someone", "example", "finally", "surface", "believe", "brought", "doesn't", "several", "english", "perhaps", "becomes", "process", "present", "looking", "there's", "carried", "friends", "minutes", "they're", "applied", "whether", "morning", "control", "explain", "measure", "foreign", "hundred", "talking", "instead", "outside", "reached", "opinion", "removed", "fingers", "project", "forward", "similar", "primary", "further", "getting", "quickly", "changes", "towards", "opening", "natural", "account", "comment", "strange", "subject", "prevent", "serious", "special", "portion", "somehow", "decided", "western", "problem", "imagine", "growing", "clearly", "beneath", "college", "exactly", "feeling", "divided", "section", "contact", "parents", "despite", "support", "healing", "neither", "attack", "better", "blocks", "bottom", "coming", "fought", "inside", "killed", "leader", "played", "player", "script", "server", "square", "should", "before", "people", "little", "didn't", "around", "really", "though", "that's", "things", "enough", "course", "always", "almost", "during", "you're", "within", "become", "behind", "matter", "others", "either", "school", "second", "friend", "system", "having", "wasn't", "public", "common", "across", "number", "moment", "passed", "person", "follow", "itself", "pretty", "making", "stupid", "growth", "result", "myself", "reason", "became", "rather", "trying", "thread", "father", "figure", "beyond", "french", "master", "family", "saying", "months", "action", "nearly", "middle", "taking", "period", "affect", "anyone", "rights", "single", "nature", "longer", "ground", "toward", "twenty", "spread", "raised", "indeed", "window", "except", "cancer", "street", "answer", "muscle", "effect", "slowly", "severe", "change", "cannot", "strong", "europe", "office", "normal", "spirit", "mother", "living", "likely", "liable", "german", "closed", "entire", "employ", "occurs", "reddit", "caught", "unless", "sudden", "please", "happen", "sounds", "simple", "nation", "filled", "points", "placed", "source", "region", "hardly", "silver", "seeing", "easily", "giving", "chance", "amount", "method", "direct", "appear", "remain", "barely", "remark", "finger", "return", "broken", "manner", "anyway", "crash", "block", "board", "chase", "fight", "later", "loose", "north", "paint", "right", "south", "speak", "splix", "spoke", "start", "worst", "esque", "cracy", "cycle", "which", "there", "their", "would", "could", "other", "about", "after", "first", "those", "these", "still", "think", "don't", "where", "being", "under", "great", "years", "while", "never", "every", "state", "again", "place", "blood", "might", "house", "shall", "until", "found", "three", "thing", "small", "power", "night", "heard", "cases", "maybe", "whole", "least", "light", "asked", "point", "world", "large", "going", "often", "can't", "known", "hands", "labor", "party", "along", "nerve", "among", "treat", "parts", "wound", "cause", "black", "taken", "money", "given", "women", "since", "above", "means", "close", "young", "times", "tried", "voice", "forms", "white", "woman", "sense", "early", "hours", "human", "death", "trade", "bones", "leave", "class", "quite", "doing", "sound", "stood", "began", "front", "wrong", "words", "local", "alone", "force", "water", "short", "takes", "mouth", "civil", "order", "occur", "peace", "paper", "lower", "clear", "heart", "terms", "doubt", "brain", "makes", "we're", "isn't", "popul", "round", "bring", "third", "cells", "meant", "child", "moved", "sorry", "sleep", "below", "floor", "watch", "seems", "whose", "earth", "heavy", "guess", "field", "sight", "upper", "issue", "lines", "weeks", "polic", "cover", "eight", "court", "lived", "stuff", "level", "space", "table", "thank", "works", "rapid", "teach", "event", "mini", "nope", "afai", "ahah", "area", "asap", "best", "chat", "died", "draw", "drew", "east", "fake", "good", "haha", "head", "imho", "keep", "kill", "left", "lmao", "mass", "near", "noob", "ping", "play", "rofl", "semi", "side", "tail", "talk", "tell", "wall", "west", "yolo", "ance", "ence", "ible", "ical", "ious", "ment", "ness", "ship", "sion", "tion", "ways", "ette", "hood", "ward", "wise", "that", "inte", "comp", "cons", "cont", "with", "from", "comm", "this", "they", "have", "disc", "tran", "were", "when", "conf", "what", "been", "into", "conc", "more", "like", "just", "conv", "unde", "dist", "them", "reco", "some", "then", "time", "your", "only", "said", "even", "than", "coun", "over", "disp", "prop", "pres", "know", "supe", "upon", "such", "back", "spec", "prot", "fore", "char", "very", "down", "made", "para", "well", "it's", "disa", "will", "most", "also", "much", "long", "same", "part", "must", "here", "make", "many", "skin", "came", "away", "hand", "ight", "once", "come", "room", "take", "face", "work", "both", "bone", "high", "last", "look", "eyes", "each", "life", "went", "knew", "ever", "took", "call", "body", "case", "give", "days", "seen", "turn", "door", "told", "name", "used", "free", "does", "year", "less", "find", "half", "mind", "felt", "i've", "seem", "next", "four", "pain", "girl", "fact", "else", "land", "done", "dark", "soon", "home", "sure", "five", "shit", "mean", "want", "kind", "gave", "stor", "need", "feel", "read", "deep", "real", "help", "able", "dead", "hard", "held", "rest", "line", "gone", "show", "rise", "fuck", "kept", "size", "true", "past", "thus", "idea", "limb", "full", "yeah", "arms", "hear", "love", "i'll", "city", "lost", "dumb", "he's", "late", "king", "farm", "form", "cold", "open", "word", "post", "neck", "term", "soft", "sent", "hope", "self", "laid", "fire", "hair", "lead", "feet", "stop", "view", "live", "none", "fear", "care", "mark", "foot", "hold", "hour", "game", "miss", "vote", "seat", "wait", "cute", "army", "easy", "step", "grew", "main", "join", "save", "move", "hunt", "says", "loss", "whom", "fell", "meat", "wish", "ones", "pass", "gold", "fine", "town", "edge", "food", "serv", "rule", "deal", "type", "ends", "we'd", "bill", "tha", "tio", "nde", "nce", "edt", "tis", "oft", "sth", "boy", "con", "yep", "afk", "aka", "art", "bad", "brb", "cya", "d/c", "die", "dot", "faq", "fyi", "gr8", "hit", "idk", "ikr", "kek", "lag", "lmc", "lol", "net", "omg", "out", "pen", "say", "sup", "thx", "top", "wtf", "'ll", "'ve", "acy", "ate", "dom", "ely", "ent", "ess", "ful", "ify", "ing", "ise", "ish", "ism", "ist", "ity", "ive", "ize", "ked", "ous", "ted", "ant", "ary", "eer", "est", "ion", "ure", "pre", "dis", "the", "pro", "com", "and", "int", "tra", "per", "sta", "res", "gra", "str", "imp", "par", "rec", "was", "cha", "ins", "sub", "exp", "ove", "you", "inc", "rep", "for", "cor", "inf", "ind", "app", "had", "mar", "his", "ste", "not", "but", "rea", "col", "und", "cla", "cou", "pla", "mis", "ass", "acc", "che", "sha", "are", "dec", "sho", "des", "spe", "tri", "har", "bra", "chi", "all", "hea", "one", "ref", "pri", "rel", "cra", "bri", "ret", "mon", "her", "bar", "she", "cre", "def", "blo", "inv", "fla", "sca", "fre", "cal", "exc", "may", "shi", "sto", "whi", "tre", "him", "wor", "han", "spi", "bla", "spo", "att", "sur", "fra", "min", "gen", "dep", "bre", "rem", "pat", "mor", "thr", "who", "rev", "ext", "pur", "its", "unc", "scr", "bur", "ser", "bal", "uns", "thi", "pos", "ele", "sen", "reg", "any", "pol", "did", "del", "mal", "sti", "has", "sch", "lea", "cat", "spa", "stu", "win", "can", "bea", "bac", "squ", "fac", "bro", "new", "now", "mas", "adv", "cri", "cap", "mat", "cur", "ver", "how", "det", "fin", "dev", "see", "emp", "our", "clo", "sec", "two", "gro", "aut", "hor", "mil", "sol", "ter", "syn", "way", "i'm", "get", "man", "too", "map", "own", "off", "war", "why", "old", "got", "uni", "saw", "few", "day", "far", "men", "met", "let", "end", "yet", "use", "put", "yes", "act", "law", "fig", "set", "i'd", "due", "cut", "son", "bed", "red", "lot", "air", "god", "arm", "ran", "guy", "ten", "try", "add", "lay", "ask", "six", "big", "ago", "eye", "sir", "age", "bit", "run", "nor", "mom", "led", "ect", "sat", "kid", "dad", "ies", "pay", "car", "hot", "low", "fix", "ics", "iel", "iar", "ian", "re", "en", "nt", "ea", "ti", "io", "le", "ou", "ar", "de", "rt", "ve", "am", "go", "of", "in", "he", "to", "it", "an", "is", "on", "at", "as", "or", "be", "me", "ha", "by", "no", "so", "we", "hi", "my", "us", "if", "do", "up", "ur", "ed", "yo", "dr", "ah", "oh", "ok", "al", "ic", "er", "nd", "es", "st", "th", "ly", "fy"]
  165.  
  166. function decToAnyRadixStr(dec, radix = 186, shift = 186) {
  167. let result = "";
  168. if (dec < 0 || dec > 0x10FFFF) return result;
  169. let r;
  170. while (dec > 0) {
  171. r = dec % radix;
  172. dec = ~~(dec / radix);
  173. if (r > 0 || dec > 0) {
  174. result += String.fromCharCode(r + shift); // + shift to avoid interpretation "bytes" as ascii chars
  175. }
  176. }
  177. return result;
  178. }
  179.  
  180. function anyRadixStrToChar(str, radix = 186) {
  181. if (str.length > 3) return "*";
  182. let i, m = 1, result = 0;
  183. for (i = 0; i < str.length; i++) {
  184. result += str.charCodeAt(i) * m;
  185. m *= radix;
  186. }
  187. if (result < 0 || result > 0x10FFFF) return "*";
  188. return String.fromCodePoint(result);
  189. }
  190.  
  191. function wordToSymbols(wordCase, wordSides, wordIndex) {
  192. var control = wordCase * 24 + wordSides * 6 + Math.floor(wordIndex / 186);
  193.  
  194. if (control < 10) { }
  195. else if (control >= 10 && control < 31) {
  196. control += 1
  197. }
  198. else if (control == 31) {
  199. control = 127
  200. }
  201. else if (control > 31 && control < 72) {
  202. control += 96;
  203. }
  204. else {
  205. return "??";
  206. }
  207. return String.fromCharCode(control) + String.fromCharCode(wordIndex % 186 + 186);
  208. }
  209.  
  210. function codesToWord(control, wordCode) {
  211. if (wordCode > 185) {
  212. console.error(\`Bad word code (\${wordCode})\`)
  213. return "<Error>"
  214. }
  215.  
  216. if (control < 10) { }
  217. else if (control >= 11 && control < 32) {
  218. control -= 1
  219. }
  220. else if (control == 127) {
  221. control = 31
  222. }
  223. else if (control > 127 && control < 168) {
  224. control -= 96
  225. }
  226. else {
  227. console.error(\`Bad control code (\${control})\`);
  228. return "<Error>";
  229. }
  230.  
  231. var wordCase = Math.floor(control / 24);
  232. var wordSides = Math.floor((control % 24) / 6);
  233. var wordIndex = (control % 6) * 186 + wordCode;
  234. var word;
  235. if (wordIndex < 1116) {
  236. var word = dict[wordIndex];
  237. }
  238. else {
  239. console.error(\`Unknown word (\${control} \${wordCode})\`)
  240. return "<Error>";
  241. }
  242. return ((wordSides < 2) ? " " : "") +
  243. ((wordCase == 0) ? word : (wordCase == 1 ? word[0].toUpperCase() + word.substring(1) : word.toUpperCase())) +
  244. ((wordSides % 2 == 0) ? " " : "");
  245. }
  246.  
  247. function prepareASCIIString(src) {
  248. var code;
  249. var result = "";
  250. src = src.normalize("NFC");
  251. for (var letter of src) {
  252. code = letter.codePointAt();
  253. if (code == 9) {
  254. result += " ";
  255. }
  256. else if ((code >= 32 && code < 127) || code == 10) {
  257. result += letter;
  258. }
  259. else if (code > 127) {
  260. var base186 = decToAnyRadixStr(code);
  261. result += String.fromCharCode(167 + base186.length) + base186;
  262. }
  263. }
  264. return result;
  265. }
  266.  
  267. function compressWithDict(src) {
  268. var dictWordLength = 0,
  269. dictPosNewLength = 0,
  270. reResult,
  271. re,
  272. srcWord,
  273. srcWordPos,
  274. srcWordLC,
  275. srcWordCase,
  276. srcWordSides,
  277. srcWordLeftSide,
  278. srcWordRightSide,
  279. rSPos,
  280. rEPos,
  281. dictPos = 0,
  282. dictPos2;
  283.  
  284. src = prepareASCIIString(src);
  285.  
  286. while (dictPos < dict.length) {
  287. dictWordLength = dict[dictPos].length;
  288. re = new RegExp(\`['A-Za-z:\\/]{\${dictWordLength}}\`, 'g');
  289.  
  290. while (dictPosNewLength < dict.length && dictWordLength == dict[dictPosNewLength].length) { dictPosNewLength++ }
  291.  
  292. while ((reResult = re.exec(src)) != null) {
  293. srcWord = reResult[0];
  294. srcWordLC = srcWord.toLowerCase();
  295. srcWordPos = reResult.index;
  296. re.lastIndex = srcWordPos + 1;
  297. for (dictPos2 = dictPos; dictPos2 < dictPosNewLength; dictPos2++) {
  298. if (dict[dictPos2] == srcWordLC) {
  299. if (srcWord == srcWordLC) { srcWordCase = 0; }
  300. else if (srcWord == srcWord[0].toUpperCase() + srcWord.substring(1).toLocaleLowerCase()) { srcWordCase = 1; }
  301. else if (srcWord == srcWord.toUpperCase()) { srcWordCase = 2; }
  302. else {
  303. break;
  304. }
  305.  
  306. srcWordLeftSide = src.substring(srcWordPos - 1, srcWordPos);
  307. srcWordRightSide = src.substring(srcWordPos + dictWordLength, srcWordPos + dictWordLength + 1);
  308. if (srcWordLeftSide == " " && srcWordRightSide == " ") { srcWordSides = 0 }
  309. else if (srcWordLeftSide == " ") { srcWordSides = 1 }
  310. else if (srcWordRightSide == " ") { srcWordSides = 2 }
  311. else if (dictWordLength > 2) { srcWordSides = 3 }
  312. else {
  313. break;
  314. }
  315.  
  316. rSPos = srcWordSides < 2 ? srcWordPos - 1 : srcWordPos;
  317. rEPos = (srcWordSides % 2 == 0) ? srcWordPos + dictWordLength + 1 : srcWordPos + dictWordLength;
  318. src = src.substring(0, rSPos) + wordToSymbols(srcWordCase, srcWordSides, dictPos2) + src.substring(rEPos);
  319.  
  320. if (srcWordSides > 1) { re.lastIndex = srcWordPos + 2; }
  321. break;
  322. }
  323. }
  324. }
  325. dictPos = dictPosNewLength;
  326. }
  327.  
  328.  
  329. let result = "";
  330. let code;
  331. for (var i = 0; i < src.length; i++) {
  332. code = src.charCodeAt(i);
  333. if (code >= 186) {
  334. result += String.fromCharCode(code - 186);
  335. }
  336. else {
  337. result += src[i];
  338. }
  339. }
  340. return result;
  341. }
  342.  
  343. function decompressWithDict(src) {
  344. var result = "",
  345. i = 0,
  346. code;
  347. while (i < src.length) {
  348. code = src.codePointAt(i);
  349. if ((code > 31 && code < 127) || code == 10) {
  350. result += src[i];
  351. i += 1;
  352. }
  353. else if (code > 167 && code <= 170) {
  354. code -= 167;
  355. result += anyRadixStrToChar(src.substring(i + 1, i + 1 + code));
  356. i += 1 + code;
  357. }
  358. else if (code > 170) {
  359. console.error(\`decompressASCII: bad code (\${code})\`);
  360. return result + " ... <Error>";
  361. }
  362. else {
  363. result += codesToWord(code, src.codePointAt(i + 1));
  364. i += 2;
  365. }
  366. }
  367. return result;
  368. }
  369.  
  370. /**
  371. * SCSU - Standard Compression Scheme for Unicode implementation for JavaScript
  372. *
  373. * Provides SCSU encoding/decoding of UTF-8 strings
  374. * Suitable for better LZF compression for UTF-8 strings
  375. * Based on Java source of SCSU by Unicode, Inc. (http:
  376. *
  377. * @class Provides methods for SCSU encoding/decoding
  378. * @author Alexey A.Znaev (znaeff@mail.ru) (http:
  379. * @copyright Copyright (C) 2011-2012 Alexey A.Znaev
  380. * @license http:
  381. * @version 1.0
  382. */
  383. function SCSU() { }
  384.  
  385. SCSU.prototype._SQ0 = 0x01;
  386. SCSU.prototype._SQ1 = 0x02;
  387. SCSU.prototype._SQ2 = 0x03;
  388. SCSU.prototype._SQ3 = 0x04;
  389. SCSU.prototype._SQ4 = 0x05;
  390. SCSU.prototype._SQ5 = 0x06;
  391. SCSU.prototype._SQ6 = 0x07;
  392. SCSU.prototype._SQ7 = 0x08;
  393.  
  394. SCSU.prototype._SDX = 0x0B;
  395. SCSU.prototype._Srs = 0x0C;
  396.  
  397. SCSU.prototype._SQU = 0x0E;
  398. SCSU.prototype._SCU = 0x0F;
  399.  
  400. SCSU.prototype._SC0 = 0x10;
  401. SCSU.prototype._SC1 = 0x11;
  402. SCSU.prototype._SC2 = 0x12;
  403. SCSU.prototype._SC3 = 0x13;
  404. SCSU.prototype._SC4 = 0x14;
  405. SCSU.prototype._SC5 = 0x15;
  406. SCSU.prototype._SC6 = 0x16;
  407. SCSU.prototype._SC7 = 0x17;
  408. SCSU.prototype._SD0 = 0x18;
  409. SCSU.prototype._SD1 = 0x19;
  410. SCSU.prototype._SD2 = 0x1A;
  411. SCSU.prototype._SD3 = 0x1B;
  412. SCSU.prototype._SD4 = 0x1C;
  413. SCSU.prototype._SD5 = 0x1D;
  414. SCSU.prototype._SD6 = 0x1E;
  415. SCSU.prototype._SD7 = 0x1F;
  416.  
  417. SCSU.prototype._UC0 = 0xE0;
  418. SCSU.prototype._UC1 = 0xE1;
  419. SCSU.prototype._UC2 = 0xE2;
  420. SCSU.prototype._UC3 = 0xE3;
  421. SCSU.prototype._UC4 = 0xE4;
  422. SCSU.prototype._UC5 = 0xE5;
  423. SCSU.prototype._UC6 = 0xE6;
  424. SCSU.prototype._UC7 = 0xE7;
  425. SCSU.prototype._UD0 = 0xE8;
  426. SCSU.prototype._UD1 = 0xE9;
  427. SCSU.prototype._UD2 = 0xEA;
  428. SCSU.prototype._UD3 = 0xEB;
  429. SCSU.prototype._UD4 = 0xEC;
  430. SCSU.prototype._UD5 = 0xED;
  431. SCSU.prototype._UD6 = 0xEE;
  432. SCSU.prototype._UD7 = 0xEF;
  433.  
  434. SCSU.prototype._UQU = 0xF0;
  435. SCSU.prototype._UDX = 0xF1;
  436. SCSU.prototype._Urs = 0xF2;
  437.  
  438. SCSU.prototype._gapThreshold = 0x68;
  439. SCSU.prototype._gapOffset = 0xAC00;
  440.  
  441. SCSU.prototype._reservedStart = 0xA8;
  442. SCSU.prototype._fixedThreshold = 0xF9;
  443.  
  444. SCSU.prototype._fixedOffset = [0x00C0, 0x0250, 0x0370, 0x0530, 0x3040, 0x30A0, 0xFF60];
  445.  
  446. SCSU.prototype._staticOffset = [0x0000, 0x0080, 0x0100, 0x0300, 0x2000, 0x2080, 0x2100, 0x3000];
  447.  
  448. SCSU.prototype._initialDynamicOffset = [0x0080, 0x00C0, 0x0400, 0x0600, 0x0900, 0x3040, 0x30A0, 0xFF00];
  449.  
  450. /**
  451. * Encodes UTF-8 string using SCSU algorithm
  452. *
  453. * @param {String} str UTF-8 string
  454. * @return {String} SCSU-encoded string
  455. * @throws {SCSUError}
  456. */
  457. SCSU.prototype.compress = function (str) {
  458. var iLen = 0, ch, ch2, iprevWindow;
  459. this._reset();
  460. this.sIn = str;
  461. this.iInLen = str.length;
  462. this.aOut = [];
  463. while (this.iIn < this.iInLen) {
  464. if (this.iSCU != -1) {
  465. ch = this._outputUnicodeRun();
  466. if (this.aOut.length - this.iSCU == 3) {
  467. this.aOut[this.iSCU] = this._SQU;
  468. this.iSCU = -1;
  469. continue;
  470. } else {
  471. this.iSCU = -1;
  472. this.fUnicodeMode = true;
  473. }
  474. } else ch = this._outputSingleByteRun();
  475. if (this.iIn == this.iInLen) break;
  476. for (var ich = this.iIn; ch < 0x80; ich++) {
  477. if (ich == this.iInLen || !this._isCompressible(this.sIn.charCodeAt(ich))) {
  478. ch = this.sIn.charCodeAt(this.iIn);
  479. break;
  480. }
  481. ch = this.sIn.charCodeAt(ich);
  482. }
  483. iprevWindow = this.iSelectedWindow;
  484. if (ch < 0x80 || this._locateWindow(ch, this.dynamicOffset)) {
  485. if (!this.fUnicodeMode && this.iIn < this.iInLen - 1) {
  486. ch2 = this.sIn.charCodeAt(this.iIn + 1);
  487. if (ch2 >= this.dynamicOffset[iprevWindow] && ch2 < this.dynamicOffset[iprevWindow] + 0x80) {
  488. this._quoteSingleByte(ch);
  489. this.iSelectedWindow = iprevWindow;
  490. continue;
  491. }
  492. }
  493. this.aOut.push(((this.fUnicodeMode ? this._UC0 : this._SC0) + this.iSelectedWindow) & 255);
  494. this.fUnicodeMode = false;
  495. } else if (!this.fUnicodeMode && this._locateWindow(ch, this._staticOffset)) {
  496. this._quoteSingleByte(ch);
  497. this.iSelectedWindow = iprevWindow;
  498. continue;
  499. } else if (this._positionWindow(ch)) {
  500. this.fUnicodeMode = false;
  501. } else {
  502. this.iSCU = this.aOut.length;
  503. this.aOut.push(this._SCU);
  504. continue;
  505. }
  506. }
  507. delete this.sIn;
  508. var a_out_symbols = [];
  509. for (var i = 0; i < this.aOut.length; i++) a_out_symbols.push(String.fromCharCode(this.aOut[i]));
  510. delete this.aOut;
  511. return a_out_symbols.join('');
  512. }
  513.  
  514. /**
  515. * Decodes SCSU-encoded string to UTF-8 one
  516. *
  517. * @param {String} str SCSU-encoded string
  518. * @return {String} UTF-8 string
  519. * @throws {SCSUError}
  520. */
  521. SCSU.prototype.decompress = function (str) {
  522. this._reset();
  523. this.sIn = str;
  524. this.iInLen = str.length;
  525. var sOut = '';
  526. var iStaticWindow, iDynamicWindow, ch;
  527. Loop:
  528. for (var iCur = 0; iCur < this.iInLen; iCur++) {
  529. iStaticWindow = 0;
  530. iDynamicWindow = this.iSelectedWindow;
  531. Switch:
  532. switch (this.sIn.charCodeAt(iCur)) {
  533. case this._SQ0:
  534. case this._SQ1:
  535. case this._SQ2:
  536. case this._SQ3:
  537. case this._SQ4:
  538. case this._SQ5:
  539. case this._SQ6:
  540. case this._SQ7:
  541. if (iCur >= this.iInLen - 1) break Loop;
  542. iDynamicWindow = iStaticWindow = this.sIn.charCodeAt(iCur) - this._SQ0;
  543. iCur++;
  544. default:
  545. if (this.sIn.charCodeAt(iCur) < 128) {
  546. ch = this.sIn.charCodeAt(iCur) + this._staticOffset[iStaticWindow];
  547. sOut += String.fromCharCode(ch);
  548. } else {
  549. ch = this.sIn.charCodeAt(iCur);
  550. ch -= 0x80;
  551. ch += this.dynamicOffset[iDynamicWindow];
  552. if (ch < 1 << 16) {
  553. sOut += String.fromCharCode(ch);
  554. } else {
  555. ch -= 0x10000;
  556. sOut += String.fromCharCode(0xD800 + (ch >> 10));
  557. sOut += String.fromCharCode(0xDC00 + (ch & ~0xFC00));
  558. }
  559. }
  560. break;
  561. case this._SDX:
  562. iCur += 2;
  563. if (iCur >= this.iInLen) break Loop;
  564. this._defineExtendedWindow(this._charFromTwoBytes(aIn[iCur - 1], this.sIn.charCodeAt(iCur)));
  565. break;
  566. case this._SD0:
  567. case this._SD1:
  568. case this._SD2:
  569. case this._SD3:
  570. case this._SD4:
  571. case this._SD5:
  572. case this._SD6:
  573. case this._SD7:
  574. iCur++;
  575. if (iCur >= this.iInLen) break Loop;
  576. this._defineWindow(this.sIn.charCodeAt(iCur - 1) - this._SD0, this.sIn.charCodeAt(iCur));
  577. break;
  578. case this._SC0:
  579. case this._SC1:
  580. case this._SC2:
  581. case this._SC3:
  582. case this._SC4:
  583. case this._SC5:
  584. case this._SC6:
  585. case this._SC7:
  586. this.iSelectedWindow = this.sIn.charCodeAt(iCur) - this._SC0;
  587. break;
  588. case this._SCU:
  589. iCur++;
  590. for (var b; iCur < this.iInLen - 1; iCur += 2) {
  591. b = this.sIn.charCodeAt(iCur);
  592. if (b >= this._UC0 && b <= this._UC7) {
  593. this.iSelectedWindow = b - this._UC0;
  594. break Switch;
  595. } else if (b >= this._UD0 && b <= this._UD7) {
  596. this._defineWindow(b - this._UD0, this.sIn.charCodeAt(iCur + 1));
  597. iCur++;
  598. break Switch;
  599. } else if (b == this._UDX) {
  600. this._defineExtendedWindow(this._charFromTwoBytes(this.sIn.charCodeAt(iCur + 1), this.sIn.charCodeAt(iCur + 2)));
  601. iCur += 2;
  602. break Switch;
  603. } else if (b == this._UQU) {
  604. iCur++;
  605. }
  606. sOut += String.fromCharCode(this._charFromTwoBytes(this.sIn.charCodeAt(iCur), this.sIn.charCodeAt(iCur + 1)));
  607. }
  608. if (iCur != this.iInLen) throw new SCSUError(this._errorText(0x11));
  609. break;
  610. case this._SQU:
  611. iCur += 2;
  612. if (iCur >= this.iInLen) {
  613. break Loop;
  614. } else {
  615. ch = this._charFromTwoBytes(this.sIn.charCodeAt(iCur - 1), this.sIn.charCodeAt(iCur));
  616. sOut += String.fromCharCode(ch);
  617. }
  618. break;
  619. case this._Srs:
  620. throw new SCSUError(this._errorText(0x16, 'Pos. ' + iCur + '.'));
  621. }
  622. }
  623. delete this.sIn;
  624. if (iCur < this.iInLen) throw new SCSUError(this._errorText(0x11));
  625. return sOut;
  626. }
  627.  
  628. SCSU.prototype._isCompressible = function (ch) {
  629. return (ch < 0x3400 || ch >= 0xE000);
  630. }
  631.  
  632. SCSU.prototype._reset = function () {
  633. this.iIn = 0;
  634. this.iSelectedWindow = 0;
  635. this.dynamicOffset = this._initialDynamicOffset.slice(0);
  636. this.iSCU = -1;
  637. this.fUnicodeMode = false;
  638. this.iNextWindow = 3;
  639. }
  640.  
  641. SCSU.prototype._locateWindow = function (ch, offsetTable) {
  642. var iWin = this.iSelectedWindow;
  643. if (iWin != - 1 && ch >= offsetTable[iWin] && ch < offsetTable[iWin] + 0x80) return true;
  644. for (iWin = 0; iWin < offsetTable.length; iWin++) {
  645. if (ch >= offsetTable[iWin] && ch < offsetTable[iWin] + 0x80) {
  646. this.iSelectedWindow = iWin;
  647. return true;
  648. }
  649. }
  650. return false;
  651. }
  652.  
  653. SCSU.prototype._isAsciiCrLfOrTab = function (ch) {
  654. return (ch >= 0x20 && ch <= 0x7F) || ch == 0x09 || ch == 0x0A || ch == 0x0D;
  655. }
  656.  
  657. SCSU.prototype._outputSingleByteRun = function () {
  658. var iWin = this.iSelectedWindow, ch, ch2, byte1, byte2, aInLen;
  659. while (this.iIn < this.iInLen) {
  660. this.iOutLen = 0;
  661. byte1 = 0;
  662. byte2 = 0;
  663. ch = this.sIn.charCodeAt(this.iIn);
  664. aInLen = 1;
  665. if ((ch & 0xF800) == 0xD800) {
  666. if ((ch & 0xFC00) == 0xDC00) {
  667. throw new SCSUError(this._errorText(0x12, 'Byte #' + this.iIn + '.'));
  668. } else {
  669. if (this.iIn >= this.iInLen - 1) throw new SCSUError(this._errorText(0x11));
  670. ch2 = this.sIn.charCodeAt(this.iIn + 1);
  671. if ((ch2 & 0xFC00) != 0xDC00) throw new SCSUError(this._errorText(0x13, 'Byte #' + (this.iIn + 1) + '.'));
  672. ch = ((ch - 0xD800) << 10 | (ch2 - 0xDC00)) + 0x10000;
  673. aInLen = 2;
  674. }
  675. }
  676. if (this._isAsciiCrLfOrTab(ch) || ch == 0) {
  677. byte2 = ch & 0x7F;
  678. this.iOutLen = 1;
  679. } else if (ch < 0x20) {
  680. byte1 = this._SQ0;
  681. byte2 = ch;
  682. this.iOutLen = 2;
  683. } else if (ch >= this.dynamicOffset[iWin] && ch < this.dynamicOffset[iWin] + 0x80) {
  684. ch -= this.dynamicOffset[iWin];
  685. byte2 = (ch | 0x80) & 255;
  686. this.iOutLen = 1;
  687. }
  688. switch (this.iOutLen) {
  689. default:
  690. return ch;
  691. case 2:
  692. this.aOut.push(byte1);
  693. case 1:
  694. this.aOut.push(byte2);
  695. break;
  696. }
  697. this.iIn += aInLen;
  698. }
  699. return 0;
  700. }
  701.  
  702. SCSU.prototype._quoteSingleByte = function (ch) {
  703. var iWin = this.iSelectedWindow, ch;
  704. this.aOut.push((this._SQ0 + iWin) & 255);
  705. if (ch >= this.dynamicOffset[iWin] && ch < this.dynamicOffset[iWin] + 0x80) {
  706. ch -= this.dynamicOffset[iWin];
  707. this.aOut.push((ch | 0x80) & 255);
  708. } else if (ch >= this._staticOffset[iWin] && ch < this._staticOffset[iWin] + 0x80) {
  709. ch -= this._staticOffset[iWin];
  710. this.aOut.push(ch & 255);
  711. } else throw new SCSUError(this._errorText(0x00, 'ch = ' + ch + ' not valid in _quoteSingleByte.'));
  712. this.iIn++;
  713. }
  714.  
  715. SCSU.prototype._outputUnicodeRun = function () {
  716. var ch = 0, ch2;
  717. while (this.iIn < this.iInLen) {
  718. ch = this.sIn.charCodeAt(this.iIn);
  719. this.iOutLen = 2;
  720. if (this._isCompressible(ch)) {
  721. if (this.iIn < this.iInLen - 1) {
  722. ch2 = this.sIn.charCodeAt(this.iIn + 1);
  723. if (this._isCompressible(ch2)) break;
  724. }
  725. if (ch >= 0xE000 && ch <= 0xF2FF) this.iOutLen = 3;
  726. }
  727. if (this.iOutLen == 3) this.aOut.push(this._UQU);
  728. this.aOut.push((ch >> 8) & 255);
  729. this.aOut.push(ch & 0xFF);
  730. this.iIn++;
  731. }
  732. return ch;
  733. }
  734.  
  735. SCSU.prototype._positionWindow = function (ch) {
  736. var iWin = this.iNextWindow % 8, iPosition = 0, ch;
  737. if (ch < 0x80) throw new SCSUError(this._errorText(0x00, 'ch < 0x80.'));
  738. for (var i = 0; i < this._fixedOffset.length; i++) {
  739. if (ch >= this._fixedOffset[i] && ch < this._fixedOffset[i] + 0x80) {
  740. iPosition = i;
  741. break;
  742. }
  743. }
  744. if (iPosition != 0) {
  745. this.dynamicOffset[iWin] = this._fixedOffset[iPosition];
  746. iPosition += 0xF9;
  747. } else if (ch < 0x3400) {
  748. iPosition = ch >> 7;
  749. this.dynamicOffset[iWin] = ch & 0xFF80;
  750. } else if (ch < 0xE000) {
  751. return false;
  752. } else if (ch <= 0xFFFF) {
  753. iPosition = ((ch - this._gapOffset) >> 7);
  754. this.dynamicOffset[iWin] = ch & 0xFF80;
  755. } else {
  756. iPosition = (ch - 0x10000) >> 7;
  757. iPosition |= iWin << 13;
  758. this.dynamicOffset[iWin] = ch & 0x1FFF80;
  759. }
  760. if (iPosition < 0x100) {
  761. this.aOut.push(((this.fUnicodeMode ? this._UD0 : this._SD0) + iWin) & 255);
  762. this.aOut.push(iPosition & 0xFF);
  763. } else if (iPosition >= 0x100) {
  764. this.aOut.push(this.fUnicodeMode ? this._UDX : this._SDX);
  765. this.aOut.push((iPosition >> 8) & 0xFF);
  766. this.aOut.push(iPosition & 0xFF);
  767. }
  768. this.iSelectedWindow = iWin;
  769. this.iNextWindow++;
  770. return true;
  771. }
  772.  
  773. SCSU.prototype._defineWindow = function (iWin, bOffset) {
  774. var iOffset = (bOffset < 0 ? bOffset + 256 : bOffset);
  775. if (iOffset == 0) {
  776. throw new SCSUError(this._errorText(0x14));
  777. } else if (iOffset < this._gapThreshold) {
  778. this.dynamicOffset[iWin] = iOffset << 7;
  779. } else if (iOffset < this._reservedStart) {
  780. this.dynamicOffset[iWin] = (iOffset << 7) + this._gapOffset;
  781. } else if (iOffset < this._fixedThreshold) {
  782. throw new SCSUError(this._errorText(0x15, 'Value = ' + iOffset + '.'));
  783. } else {
  784. this.dynamicOffset[iWin] = this._fixedOffset[iOffset - this._fixedThreshold];
  785. }
  786. this.iSelectedWindow = iWin;
  787. }
  788.  
  789. SCSU.prototype._defineExtendedWindow = function (chOffset) {
  790. var iWin = chOffset >> 13;
  791. this.dynamicOffset[iWin] = ((chOffset & 0x1FFF) << 7) + (1 << 16);
  792. this.iSelectedWindow = iWin;
  793. }
  794.  
  795. SCSU.prototype._charFromTwoBytes = function (hi, lo) {
  796. var ch = (lo >= 0 ? lo : 256 + lo);
  797. return (ch + ((hi >= 0 ? hi : 256 + hi) << 8));
  798. }
  799.  
  800. SCSU.prototype._ERRORS = {
  801. 0x00: 'Internal error.',
  802. 0x10: 'Illegal input.',
  803. 0x11: 'Ended prematurely.',
  804. 0x12: 'Unpaired low surrogate.',
  805. 0x13: 'Unpaired high surrogate.',
  806. 0x14: 'Zero offset.',
  807. 0x15: 'Bad offset.',
  808. 0x16: 'Srs byte found.',
  809. 0x20: 'Bad output.'
  810. };
  811.  
  812. SCSU.prototype._errorText = function (code, text) {
  813. if (code == null || (typeof code != 'number') || code < 0 || code > 0xFF) code = 0x00;
  814. if (text == null || (typeof text != 'string')) text = '';
  815. var message = '';
  816. var code_class = code & 0xF0;
  817. if (this._ERRORS[code_class]) message = this._ERRORS[code_class];
  818. if ((code != code_class) && this._ERRORS[code]) message += ' ' + this._ERRORS[code];
  819. return ('SCSU 0x' + code.toString(16) + ': ' + message + (text == '' ? '' : ' ') + text);
  820. }
  821.  
  822. /**
  823. * SCSU Errors exceptions
  824. *
  825. * @class Constructs exceptions of SCSU errors
  826. * @author Alexey A.Znaev (znaeff@mail.ru) (http:
  827. * @copyright Copyright (C) 2011-2012 Alexey A.Znaev
  828. * @license http:
  829. * @version 1.0
  830. */
  831. function SCSUError(msg) { this.message = msg; this.name = 'SCSUError' };
  832. SCSUError.prototype = new Error();
  833.  
  834. function removeControlASCIISymbols(str) {
  835. var code;
  836. var result = "";
  837. for (var i = 0; i < str.length; i++) {
  838. code = str.codePointAt(i);
  839. if (code == 9) {
  840. result += " ";
  841. }
  842. else if ((code >= 32 && code < 127) || code > 127 || code == 10) {
  843. result += str[i]
  844. }
  845. }
  846. return result;
  847. }
  848.  
  849. function compressWithSCSU(src) {
  850. src = removeControlASCIISymbols(src);
  851. var result;
  852. try {
  853. result = SCSU.prototype.compress(src);
  854. }
  855. catch (e) {
  856. console.error("SCSU compression error:", e);
  857. return null;
  858. }
  859. return result;
  860. }
  861.  
  862. function decompressWithSCSU(src) {
  863. var result;
  864. try {
  865. result = SCSU.prototype.decompress(src);
  866. }
  867. catch (e) {
  868. //console.error("SCSU decompression error:", e);
  869. return null;
  870. }
  871. return result;
  872. }
  873.  
  874. function unicodeToRadix183Str(src) {
  875. var result = "",
  876. code;
  877. for (var letter of src) {
  878. code = letter.codePointAt();
  879. if (code < 183) {
  880. result += letter;
  881. }
  882. else if (code > 127) {
  883. var base183 = decToAnyRadixStr(code, 183, 0);
  884. result += String.fromCharCode(182 + base183.length) + base183;
  885. }
  886. }
  887. return result;
  888. }
  889.  
  890. function radix183StrToUnicode(src) {
  891. var result = "",
  892. i = 0,
  893. code;
  894. while (i < src.length) {
  895. code = src.codePointAt(i);
  896. if (code < 183) {
  897. result += src[i];
  898. i += 1;
  899. }
  900. else {
  901. code -= 182;
  902. result += anyRadixStrToChar(src.substring(i + 1, i + 1 + code), 183, 0);
  903. i += 1 + code;
  904. }
  905. }
  906. return result;
  907. }
  908.  
  909. function strToHonkMsg(src) {
  910. var encodingType,
  911. result;
  912.  
  913. if (src.length == 0) {
  914. encodingType = 3;
  915. result = " ";
  916. }
  917. else {
  918. var codedWithDict = compressWithDict(src);
  919. var codedWithoutDict = compressWithSCSU(src);
  920.  
  921. var scsu = false;
  922. if (codedWithoutDict !== null) {
  923. if (decompressWithSCSU(codedWithoutDict) !== null) {
  924. codedWithoutDict = unicodeToRadix183Str(codedWithoutDict);
  925. scsu = true;
  926. }
  927. }
  928.  
  929. if (!scsu) {
  930. codedWithoutDict = unicodeToRadix183Str(src);
  931. }
  932.  
  933. if (codedWithDict.length < codedWithoutDict.length) {
  934. result = codedWithDict;
  935. encodingType = 1;
  936. }
  937. else {
  938. result = codedWithoutDict;
  939. encodingType = scsu ? 2 : 3;
  940. }
  941. }
  942.  
  943. if (result.length > 186 || result.length < 1) {
  944. return result.length;
  945. }
  946. else {
  947. return String.fromCharCode(encodingType) + String.fromCharCode(result.length - 1) + result;
  948. }
  949. }
  950.  
  951. function honkMsgToString(src) {
  952. const errMsg = "<Decoding error>";
  953. var srcLen = src.length,
  954. result = "";
  955. if (srcLen < 3 || srcLen > 186 + 2) {
  956. console.error(\`honkMsgToString: incorrect length of source (\${src.length})\`);
  957. return errMsg;
  958. }
  959. else {
  960. var encodingType = src.codePointAt(0);
  961. if (encodingType < 1 || encodingType > 3) {
  962. console.error(\`honkMsgToString: incorrect encoding type (\${encodingType})\`);
  963. return errMsg;
  964. }
  965.  
  966. var textLen = src.codePointAt(1);
  967. if (srcLen - 2 != textLen) {
  968. console.error(\`honkMsgToString: incorrect message text length (\${srcLen} / \${textLen})\`);
  969. return errMsg;
  970. }
  971.  
  972. try {
  973. if (encodingType == 1) {
  974. result = decompressWithDict(src.substring(2));
  975. }
  976. else if (encodingType == 2) {
  977. result = decompressWithSCSU(radix183StrToUnicode(src.substring(2)));
  978. }
  979. else if (encodingType == 3) {
  980. result = radix183StrToUnicode(src.substring(2));
  981. }
  982.  
  983. return result.replace(/(\\r\\n|\\r|\\n){2,}/g, '\$1\\n');
  984. }
  985. catch (e) {
  986. console.error(\`honkMsgToString: decompression error (type \${encodingType})\`, e);
  987. return errMsg;
  988. }
  989. }
  990. }
  991.  
  992. var wcMessage = "";
  993. var wcMessagePos = 0;
  994.  
  995. function wcSendMsgHonk() {
  996. if (playingAndReady) {
  997. var code = wcMessage.charCodeAt(wcMessagePos) + 70;
  998. wcMessagePos += 1;
  999. if (!wsSendMsg(sendAction.HONK, code)) wsMsgSendStatus = 0;
  1000. myPlayer.doHonk(code);
  1001. if (wcMessagePos < wcMessage.length) {
  1002. setTimeout(wcSendMsgHonk, ((wcMessagePos < 13e0) ? 50e0 : ((wcMessagePos < 26e0) ? 65e0 : 85e0)));
  1003. }
  1004. else {
  1005. wsMsgSendStatus = 0;
  1006. }
  1007. }
  1008. else {
  1009. wsMsgSendStatus = 0;
  1010. }
  1011. }
  1012.  
  1013. function wcSendMessage(message) {
  1014. wcMessage = String.fromCharCode(1) + String.fromCharCode(57) + message;
  1015. wcMessagePos = 0;
  1016. wsMsgSendStatus = 1;
  1017. wcSendMsgHonk();
  1018. }
  1019.  
  1020. function wcMsgHonkHandler(player, value) {
  1021. if (player.msgStatus == 0) {
  1022. if (value == 71 && !wcIsPlayerBlocked(player.name, player.skinBlock)) {
  1023. player.msgStatus = 1;
  1024. }
  1025. else return;
  1026. }
  1027. else if (player.msgStatus == 1) {
  1028. if (value == 127) {
  1029. player.msgStatus = 2;
  1030. }
  1031. else if (value !== 71) {
  1032. player.msgStatus = 0;
  1033. }
  1034. }
  1035. else if (player.msgStatus == 2) {
  1036. if (value >= 71 && value <= 73) {
  1037. player.msgStatus = 3;
  1038. player.message = String.fromCharCode(value - 70);
  1039. }
  1040. else {
  1041. player.msgStatus = 0;
  1042. }
  1043. }
  1044. else if (player.msgStatus == 3) {
  1045. player.msgStatus = 4;
  1046. player.msgLength = value - 69 + 2;
  1047. player.message += String.fromCharCode(value - 69);
  1048. }
  1049. else {
  1050. player.message += String.fromCharCode(value - 70);
  1051. if (player.message.length >= player.msgLength) {
  1052. wcNewMessage(player.message, player.name, player.skinBlock);
  1053. player.msgStatus = 0;
  1054. }
  1055. }
  1056. }
  1057.  
  1058. function honkEndWC() {
  1059. if (wsMsgSendStatus === 0) {
  1060. var e = Date.now();
  1061. if (lastHonkTime < e) {
  1062. var t = clamp(t = e - honkStartTime, 0, 1e3);
  1063. lastHonkTime = e + t,
  1064. t = iLerp(0, 1e3, t),
  1065. t *= 255,
  1066. t = Math.floor(t),
  1067. wsSendMsg(sendAction.HONK, t);
  1068. for (var n = 0; n < players.length; n++) {
  1069. var a = players[n];
  1070. a.isMyPlayer && a.doHonk(Math.max(70, t))
  1071. }
  1072. }
  1073. }
  1074. }
  1075.  
  1076. function getPlayerWC(e, t) {
  1077. var n;
  1078. void 0 === t && (t = players);
  1079. for (var a = 0; a < t.length; a++)
  1080. if ((n = t[a]).id == e)
  1081. return n;
  1082. return n = {
  1083. id: e,
  1084. pos: [0, 0],
  1085. drawPos: [-1, -1],
  1086. drawPosSet: !1,
  1087. serverPos: [0, 0],
  1088. dir: 0,
  1089. isMyPlayer: 0 === e,
  1090. isDead: !1,
  1091. deathWasCertain: !1,
  1092. didUncertainDeathLastTick: !1,
  1093. isDeadTimer: 0,
  1094. uncertainDeathPosition: [0, 0],
  1095. message: "",
  1096. msgStatus: 0,
  1097. msgLength: 0,
  1098. die: function (e) {
  1099. if (e = !!e, this.isDead)
  1100. this.deathWasCertain = e || this.deathWasCertain;
  1101. else if (e || !this.didUncertainDeathLastTick) {
  1102. e || (this.didUncertainDeathLastTick = !0, this.uncertainDeathPosition = [this.pos[0], this.pos[1]]),
  1103. this.isDead = !0,
  1104. this.deathWasCertain = e,
  1105. this.deadAnimParts = [0],
  1106. this.isDeadTimer = 0,
  1107. this.isMyPlayer && doCamShakeDir(this.dir);
  1108. for (var t = 0; ;) {
  1109. if ((t += .4 * Math.random() + .5) >= 2 * Math.PI) {
  1110. this.deadAnimParts.push(2 * Math.PI);
  1111. break
  1112. }
  1113. this.deadAnimParts.push(t),
  1114. this.deadAnimPartsRandDist.push(Math.random())
  1115. }
  1116. }
  1117. },
  1118. undoDie: function () {
  1119. this.isDead = !1
  1120. },
  1121. deadAnimParts: [],
  1122. deadAnimPartsRandDist: [],
  1123. addHitLine: function (e, t) {
  1124. this.hitLines.push({
  1125. pos: e,
  1126. vanishTimer: 0,
  1127. color: t
  1128. })
  1129. },
  1130. hitLines: [],
  1131. doHonk: function (e) {
  1132. this.honkTimer = 0,
  1133. this.honkMaxTime = e,
  1134. "joris" == this.name.toLowerCase() && (null == honkSfx && (honkSfx = new Audio("/static/honk.mp3")), honkSfx.play());
  1135. wcMsgHonkHandler(this, e);
  1136. },
  1137. moveRelativeToServerPosNextFrame: !1,
  1138. lastServerPosSentTime: 0,
  1139. honkTimer: 0,
  1140. honkMaxTime: 0,
  1141. trails: [],
  1142. name: "",
  1143. skinBlock: 0,
  1144. lastBlock: null,
  1145. hasReceivedPosition: !1
  1146. },
  1147. t.push(n),
  1148. n.isMyPlayer && (myPlayer = n),
  1149. n
  1150. }
  1151.  
  1152. getPlayer = getPlayerWC;
  1153. honkEnd = honkEndWC;
  1154.  
  1155. var style = \`
  1156. #chatbox {
  1157. position: fixed;
  1158. right: 0;
  1159. bottom: 0;
  1160. }
  1161.  
  1162. #chatbox > * {
  1163. clear:both;
  1164. float:right;
  1165. }
  1166.  
  1167. #chatMessages > * {
  1168. clear:both;
  1169. float:right;
  1170. }
  1171.  
  1172. #chatNotifications > * {
  1173. clear:both;
  1174. float:right;
  1175. }
  1176.  
  1177. .chatMessage, .chatNotification {
  1178. display: flex;
  1179. background: #2d2824;
  1180. border: solid 2px #332d29;
  1181. margin: 1px 7px;
  1182. border-radius: 9px;
  1183. overflow: hidden;
  1184. max-width: 450px;
  1185. user-select: text;
  1186. opacity: 1;
  1187. }
  1188.  
  1189. .chatNotification {
  1190. max-height: 100px;
  1191. }
  1192.  
  1193. .chatNotification > span {
  1194. color: #fff;
  1195. font-style: italic;
  1196. display: flex;
  1197. align-items: center;
  1198. padding: 4px 10px;
  1199. }
  1200.  
  1201. #chatInput {
  1202. display: inline-block;
  1203. background: #7a6d62;
  1204. color: #000000;
  1205. border: solid 4px #3a342f;
  1206. margin: 1px 0 0 0;
  1207. padding: 0 0.2em;
  1208. font-size: 1.1em;
  1209. line-height: 1.4em;
  1210. outline: none;
  1211. min-width: 250px;
  1212. font-family: "Lucida Console", Monaco, monospace;
  1213. visibility: hidden;
  1214. }
  1215.  
  1216. .chatMessage > span {
  1217. display: flex;
  1218. align-items: center;
  1219. padding-top: 4px;
  1220. padding-bottom: 4px;
  1221. }
  1222.  
  1223. .chatMessage span:last-of-type{
  1224. color: #fff;
  1225. background: #413a35;
  1226. padding-left: 10px;
  1227. padding-right: 10px;
  1228. overflow-wrap: anywhere;
  1229. }
  1230.  
  1231. .chatMessage span:first-of-type{
  1232. color: #ffffff80;
  1233. font-weight: bold;
  1234. padding-left: 5px;
  1235. padding-right: 5px;
  1236. cursor: pointer;
  1237. max-width: 300px;
  1238. }
  1239.  
  1240. #wcBlock {
  1241. position: fixed;
  1242. min-width: 300px;
  1243. background: #4d453e;
  1244. border: solid 1px #000000;
  1245. color: #ffffff;
  1246. text-align: center;
  1247. box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.1);
  1248. cursor: default;
  1249. user-select: none;
  1250. overflow: hidden;
  1251. font-size: 0;
  1252. opacity: 0;
  1253. display: none;
  1254. transition: font-size 0.15s ease-out, opacity 0.05s ease-out 0.05s;
  1255. right: 100px;
  1256. bottom: 100px;
  1257. }
  1258.  
  1259. #wcBlock input[type="checkbox"],
  1260. #wcBlock input[type="radio"] {
  1261. display: none;
  1262. }
  1263.  
  1264. #wcBlock label {
  1265. padding: 0.9em 0.2em;
  1266. }
  1267.  
  1268. #wcBlock input[type="radio"]:checked+label {
  1269. background: #a22929;
  1270. }
  1271.  
  1272. #wcBlock input:hover+label {
  1273. background: #3a342f;
  1274. }
  1275.  
  1276. #wcBlockAttributes input+label::before {
  1277. content: 'Current ';
  1278. }
  1279.  
  1280. #wcBlockAttributes input:checked+label::before {
  1281. content: 'Any ';
  1282. }
  1283.  
  1284. #wcBlockHeader {
  1285. background: #3a342f;
  1286. font-weight: bold;
  1287. padding: 0.3em 0.3em;
  1288. }
  1289.  
  1290. #wcBlockPeriod,
  1291. #wcBlockAttributes,
  1292. #wcBlockButtons {
  1293. display: grid;
  1294. }
  1295.  
  1296. #wcBlockPeriod {
  1297. grid-template-columns: 23% 23% 23% 31%;
  1298. }
  1299.  
  1300. #wcBlockButtons {
  1301. grid-template-columns: 59% 40%;
  1302. column-gap: 1%;
  1303. }
  1304.  
  1305. .wcBlockButton {
  1306. background: #3a342f;
  1307. border: none;
  1308. padding: 0.6em 0.1em;
  1309. color: white;
  1310. font-size: 1em;
  1311. }
  1312.  
  1313. #wcBlockBlock {
  1314. background: #631717;
  1315. }
  1316.  
  1317. #wcBlockCancel:hover {
  1318. background: #3bad48;
  1319. }
  1320.  
  1321. #wcBlockBlock:hover {
  1322. background: #a22929;
  1323. }
  1324. \`
  1325.  
  1326. addStyle(style);
  1327.  
  1328. var html = \`
  1329. <div id="chatbox">
  1330. <div id="chatMessages"></div>
  1331. <div id="chatNotifications"></div>
  1332. <input id="chatInput" type="text" maxlength="372">
  1333. </div>
  1334. <div id="wcBlock">
  1335. <div id="wcBlockHeader">Block user for ...</div>
  1336. <div id="wcBlockPeriod">
  1337. <input class="wcBlockPeriodRadio" type="radio" name="wcBlockPeriod" value="year" id="wcBlockPeriodRadio1">
  1338. <label for="wcBlockPeriodRadio1">Year</label>
  1339. <input class="wcBlockPeriodRadio" type="radio" name="wcBlockPeriod" value="week" id="wcBlockPeriodRadio2">
  1340. <label for="wcBlockPeriodRadio2">Week</label>
  1341. <input class="wcBlockPeriodRadio" type="radio" name="wcBlockPeriod" value="day" id="wcBlockPeriodRadio3">
  1342. <label for="wcBlockPeriodRadio3">Day</label>
  1343. <input class="wcBlockPeriodRadio" type="radio" name="wcBlockPeriod" value="2h" id="wcBlockPeriodRadio4" checked>
  1344. <label for="wcBlockPeriodRadio4">Two&nbsp;hours</label>
  1345. </div>
  1346. <div id="wcBlockAttributes">
  1347. <input class="wcBlockAttribute" type="checkbox" id="wcBlockAnyColor" checked>
  1348. <label for="wcBlockAnyColor">color</label>
  1349. </div>
  1350. <div id="wcBlockButtons">
  1351. <input class="wcBlockButton" type="button" id="wcBlockBlock" value="Block">
  1352. <input class="wcBlockButton" type="button" id="wcBlockCancel" value="Cancel">
  1353. </div>
  1354. </div>
  1355. \`
  1356.  
  1357. addHTML(html, "#playUI");
  1358.  
  1359. var wcBlock = document.getElementById("wcBlock");
  1360. var wcPlayerMenuHeader = document.getElementById("wcBlockHeader");
  1361. var wcBlockPeriodRadio1 = document.getElementById("wcBlockPeriodRadio1");
  1362. var wcBlockPeriodRadio2 = document.getElementById("wcBlockPeriodRadio2");
  1363. var wcBlockPeriodRadio3 = document.getElementById("wcBlockPeriodRadio3");
  1364. var wcBlockPeriodRadio4 = document.getElementById("wcBlockPeriodRadio4");
  1365. var wcBlockAnyColor = document.getElementById("wcBlockAnyColor");
  1366. var wcBlockBlock = document.getElementById("wcBlockBlock");
  1367. var wcBlockCancel = document.getElementById("wcBlockCancel");
  1368.  
  1369. wcBlockAnyColor.addEventListener("change", function () {
  1370. if (!wcBlockAnyColor.checked) {
  1371. document.querySelector("#wcBlockAnyColor+label").style.backgroundColor = wcBlock.getAttribute("data-color");
  1372. }
  1373. else {
  1374. document.querySelector("#wcBlockAnyColor+label").style.background = "none";
  1375. }
  1376. })
  1377.  
  1378. function wcShowBlockMenu(e) {
  1379. var name = e.target.getAttribute("data-name");
  1380. var colorId = e.target.getAttribute("data-colorid");
  1381. wcBlock.setAttribute("data-name", name);
  1382. wcBlock.setAttribute("data-color", bgColorById(colorId));
  1383. wcBlock.setAttribute("data-colorid", colorId);
  1384. wcPlayerMenuHeader.textContent = \`Block \${name} for a...\`;
  1385. wcBlockPeriodRadio4.checked = true;
  1386. wcBlockAnyColor.checked = false;
  1387. document.querySelector("#wcBlockAnyColor+label").style.backgroundColor = bgColorById(colorId);
  1388. wcBlock.style.right = \`\${document.body.clientWidth - e.clientX + 20}px\`
  1389. wcBlock.style.bottom = \`\${document.body.clientHeight - e.clientY}px\`
  1390. wcBlock.style.opacity = "1";
  1391. wcBlock.style.fontSize = "1em";
  1392. wcBlock.style.display = "block";
  1393. }
  1394.  
  1395. function wcHideBlockMenu() {
  1396. wcBlock.style.opacity = "0";
  1397. wcBlock.style.fontSize = "0";
  1398. wcBlock.style.display = "none";
  1399. }
  1400.  
  1401. wcBlockCancel.addEventListener("click", wcHideBlockMenu);
  1402. wcBlockBlock.addEventListener("click", function () {
  1403. var until = Date.now() +
  1404. (wcBlockPeriodRadio4.checked ? 2 * 60 * 60 * 1000 :
  1405. (wcBlockPeriodRadio3.checked ? 24 * 60 * 60 * 1000 :
  1406. (wcBlockPeriodRadio2.checked ? 7 * 24 * 60 * 60 * 1000 :
  1407. 365 * 24 * 60 * 60 * 1000)));
  1408.  
  1409. var name = wcBlock.getAttribute("data-name");
  1410. var colorId = !(wcBlockAnyColor.checked) ? Number.parseInt(wcBlock.getAttribute("data-colorid")) : -1;
  1411. if (isNaN(colorId)) {
  1412. colorId = -1;
  1413. }
  1414. wcBlockPlayer(name, until, colorId);
  1415.  
  1416. wcNewNotification(\`\${name} has been blocked\`, 6);
  1417. wcHideBlockMenu();
  1418. });
  1419.  
  1420. var chatNotifications = document.getElementById("chatNotifications");
  1421. var chatMessages = document.getElementById("chatMessages");
  1422. var chatInput = document.getElementById("chatInput");
  1423. chatInput.addEventListener('input', resizeChatInput);
  1424.  
  1425. function resizeChatInput() {
  1426. chatInput.style.width = (chatInput.value.length + 1) + "ch";
  1427. }
  1428.  
  1429. function addStyle(styleStr) {
  1430. const style = document.createElement('style');
  1431. style.textContent = styleStr;
  1432. document.head.append(style);
  1433. }
  1434.  
  1435. function addHTML(htmlStr, selector) {
  1436. var template = document.createElement('template');
  1437. template.innerHTML = htmlStr.trim();
  1438. document.querySelector(selector).appendChild(template.content);
  1439. }
  1440.  
  1441. function bgColorById(colorId) {
  1442. if (colorId < 0 || colorId > 12) { return 0 }
  1443. var hue = [0, 342.9, 322.81, 265.97, 274.04, 227.18, 218.93, 125.19, 126.95, 71.69, 49.88, 27.39, 40.99];
  1444. return \`hsl(\${hue[colorId]}, 94%, 50%)\`;
  1445. }
  1446.  
  1447. function colorNameById(colorId) {
  1448. if (colorId < 0 || colorId > 12) { return "" }
  1449. var colors = ["red", "pink", "dark pink", "light purple", "dark purple", "dark blue", "light blue", "light green", "dark green", "olive", "yellow", "orange", "gold"];
  1450. return (colors[colorId]);
  1451. }
  1452.  
  1453. var msgDivs = [];
  1454. var notifDivs = [];
  1455. var wsMsgSendStatus = 0;
  1456. var chatVisible = true;
  1457. var showPrivacyWarning = wcFlags.wcPrivacyWarnings;
  1458. removeExtraMessages();
  1459.  
  1460. function wcPrivacyWarning() {
  1461. var strings = [
  1462. "Walls have ears, and so do blocks",
  1463. "Do not pass any important information through this chat",
  1464. "The interlocutor may not be who he seems",
  1465. ];
  1466. var emojis = ["👀", "🤐", "🎭", "👺", "👂", "🕵️"];
  1467. wcNewNotification(strings[Math.floor(Math.random() * strings.length)] + " " + emojis[Math.floor(Math.random() * emojis.length)], 10, 1);
  1468. showPrivacyWarning = false;
  1469. }
  1470.  
  1471. function wcNewMessage(honkMsg, name, colorId) {
  1472. if (showPrivacyWarning) {
  1473. wcPrivacyWarning();
  1474. }
  1475. var color = bgColorById(colorId);
  1476. var text = wcCompatibleReplace(honkMsgToString(honkMsg));
  1477. var trimName = name.trim();
  1478. if (wcFlags.wcConsoleLog) {
  1479. console.log(new Date().toLocaleTimeString(wcFlags.wcConsoleLogTimeAmPm ? "en-US" : "en-GB", { timeStyle: "short" }) + " " +
  1480. (trimName === "" ? \`(\${colorNameById(colorId)})\` : trimName) + ": " + text);
  1481. }
  1482.  
  1483. var msgDiv = document.createElement("div");
  1484. msgDiv.classList.add("chatMessage");
  1485.  
  1486. var msgSpanName = document.createElement("span");
  1487. msgSpanName.textContent = trimName === "" ? "⬤" : trimName;
  1488. msgSpanName.setAttribute("data-name", trimName);
  1489. msgSpanName.setAttribute("data-colorid", colorId);
  1490. msgSpanName.style.color = color;
  1491. msgSpanName.addEventListener("click", wcShowBlockMenu);
  1492. var msgSpanText = document.createElement("span");
  1493. msgSpanText.textContent = text;
  1494. msgDiv.appendChild(msgSpanName);
  1495. msgDiv.appendChild(msgSpanText);
  1496. chatMessages.appendChild(msgDiv);
  1497. msgDivs.unshift(msgDiv);
  1498. if (wcFlags.wcMsgDisplayTime !== 0) { // don't delete at all if 0. But will be deleted if limit reached
  1499. setTimeout(function () {
  1500. msgDiv.style.transition = \`opacity \${wcFlags.wcMsgDecayTime <= wcFlags.wcMsgDisplayTime ? wcFlags.wcMsgDecayTime : wcFlags.wcMsgDisplayTime}s ease-in-out\`;
  1501. msgDiv.style.opacity = "0";
  1502. }, (wcFlags.wcMsgDecayTime < wcFlags.wcMsgDisplayTime ? wcFlags.wcMsgDisplayTime - wcFlags.wcMsgDecayTime : 0.1) * 1000);
  1503. setTimeout(function () {
  1504. var index = msgDivs.indexOf(msgDiv);
  1505. if (index != -1) {
  1506. msgDiv.remove();
  1507. msgDivs.splice(index, 1);
  1508. }
  1509. }, wcFlags.wcMsgDisplayTime * 1000);
  1510. }
  1511. }
  1512.  
  1513. function showTopNotification(text, timeAlive = 4) {
  1514. var notification = doTopNotification(text);
  1515. setTimeout(function () { notification.animateOut(); notification.destroy(); }, timeAlive * 1000);
  1516. }
  1517.  
  1518. function wcNewCornerNotification(text, timeAlive = 4, type = 0) {
  1519. var notifDiv = document.createElement("div");
  1520. notifDiv.classList.add("chatNotification");
  1521. var notifSpan = document.createElement("span");
  1522. notifSpan.textContent = text;
  1523. if (type == 1) {
  1524. notifSpan.style.fontStyle = "normal";
  1525. notifSpan.style.color = "yellow";
  1526. }
  1527. notifDiv.appendChild(notifSpan);
  1528. chatNotifications.appendChild(notifDiv);
  1529. notifDivs.unshift(notifDiv);
  1530. setTimeout(function () {
  1531. notifDiv.style.transition = "opacity 1s ease-in-out, max-height .35s ease-in-out";
  1532. notifDiv.style.transitionDelay = "0s, .5s"
  1533. notifDiv.style.opacity = "0";
  1534. notifDiv.style.maxHeight = "0";
  1535. }, (timeAlive - 1) * 1000);
  1536. setTimeout(function () {
  1537. var index = notifDivs.indexOf(notifDiv);
  1538. if (index != -1) {
  1539. notifDiv.remove();
  1540. notifDivs.splice(index, 1);
  1541. }
  1542. }, timeAlive * 1000);
  1543. }
  1544.  
  1545. function wcNewNotification(text, timeAlive = 4, type = 0) {
  1546. text = wcCompatibleReplace(text);
  1547.  
  1548. if (timeAlive == undefined) {
  1549. timeAlive = 4;
  1550. }
  1551. if (wcFlags.wcDefaultNotifications) {
  1552. showTopNotification(text, timeAlive);
  1553. }
  1554. else {
  1555. wcNewCornerNotification(text, timeAlive, type);
  1556. }
  1557. }
  1558.  
  1559. function removeExtraMessages() {
  1560. if (msgDivs.length > wcFlags.wcMessageLimit) {
  1561. for (var i = msgDivs.length - 1; i > wcFlags.wcMessageLimit; i--) {
  1562. msgDivs[i].remove();
  1563. msgDivs.splice(i);
  1564. }
  1565. }
  1566. setTimeout(removeExtraMessages, 2000);
  1567. }
  1568.  
  1569. function hideChatInput() {
  1570. chatInput.style.visibility = 'hidden';
  1571. chatInput.blur();
  1572. }
  1573.  
  1574. function toggleChatInput() {
  1575. if (chatInput.style.visibility !== 'visible') {
  1576. chatInput.style.visibility = 'visible';
  1577. showChat();
  1578. chatInput.focus();
  1579. if (document.activeElement !== chatInput) hideChatInput();
  1580. }
  1581. else {
  1582. hideChatInput();
  1583. }
  1584. }
  1585.  
  1586. function showChat() {
  1587. chatVisible = true;
  1588. chatMessages.style.opacity = '1';
  1589. chatMessages.style.pointerEvents = 'auto';
  1590. }
  1591.  
  1592. function toggleChat() {
  1593. chatVisible = !chatVisible;
  1594. if (chatVisible) {
  1595. chatMessages.style.opacity = '1';
  1596. chatMessages.style.pointerEvents = 'auto';
  1597. wcNewNotification("Chat is visible", 2);
  1598. }
  1599. else {
  1600. chatMessages.style.opacity = '0';
  1601. chatMessages.style.pointerEvents = 'none';
  1602. hideChatInput();
  1603. wcNewNotification("Chat is hidden", 2);
  1604. }
  1605. }
  1606.  
  1607. function wcIsPlayerBlocked(name, colorId) {
  1608. if (!(name in wcFlags.wcBlockedPlayers)) {
  1609. return false;
  1610. }
  1611. else {
  1612. for (const one of wcFlags.wcBlockedPlayers[name]) {
  1613. if (one.until > Date.now() && (!('colorId' in one) || one.colorId == colorId)) {
  1614. return true;
  1615. }
  1616. }
  1617. }
  1618. return false;
  1619. }
  1620.  
  1621. function wcBlockPlayer(name, until, colorId = -1) {
  1622. wcLoadBlockedPlayers(false);
  1623.  
  1624. if (!(name in wcFlags.wcBlockedPlayers)) {
  1625. wcFlags.wcBlockedPlayers[name] = [];
  1626. }
  1627.  
  1628. if (colorId === -1) {
  1629. wcFlags.wcBlockedPlayers[name].push({ 'until': until });
  1630. }
  1631. else {
  1632. wcFlags.wcBlockedPlayers[name].push({ 'until': until, 'colorId': colorId });
  1633. }
  1634. wcSaveBlockedPlayers();
  1635. }
  1636.  
  1637. function wcSaveBlockedPlayers() {
  1638. localStorage.setItem("wcBlockedPlayers", JSON.stringify(wcFlags.wcBlockedPlayers));
  1639. }
  1640.  
  1641. function wcLoadBlockedPlayers(saveIfChanged = true) {
  1642. var lsBlockedPlayers = localStorage.getItem("wcBlockedPlayers");
  1643. var wasChanged = false;
  1644.  
  1645. try {
  1646. var parsedBlockedPlayers = JSON.parse(lsBlockedPlayers);
  1647. if (parsedBlockedPlayers === null) {
  1648. parsedBlockedPlayers = {}
  1649. }
  1650. }
  1651. catch {
  1652. var parsedBlockedPlayers = {};
  1653. wasChanged = true;
  1654. }
  1655.  
  1656. for (var name in parsedBlockedPlayers) {
  1657. const properties = parsedBlockedPlayers[name];
  1658. if (Array.isArray(properties)) {
  1659. var i = properties.length;
  1660. while (i--) {
  1661. const one = properties[i];
  1662. if (typeof one !== 'object'
  1663. || one === null
  1664. || !('until' in one)
  1665. || one.until < Date.now()
  1666. || ('colorId' in one && (!Number.isInteger(one.colorId) || one.colorId < 0 || one.colorId > 12))) {
  1667. properties.splice(i, 1);
  1668. wasChanged = true;
  1669. }
  1670. }
  1671. if (properties.length === 0) {
  1672. delete parsedBlockedPlayers[name];
  1673. wasChanged = true;
  1674. }
  1675. }
  1676. else {
  1677. delete parsedBlockedPlayers.name;
  1678. wasChanged = true;
  1679. }
  1680. }
  1681.  
  1682. wcFlags.wcBlockedPlayers = parsedBlockedPlayers;
  1683.  
  1684. if (saveIfChanged && wasChanged) {
  1685. wcSaveBlockedPlayers();
  1686. }
  1687. }
  1688.  
  1689. var wcReplacements = {}, wcRECompat, wcCompatibleReplace;
  1690.  
  1691. (function () {
  1692. var compatibleReplacements = {
  1693. "💔": ["</3"],
  1694. "😕": [":-/"],
  1695. "😢": [":'("],
  1696. "🙁": ["😟", ":("],
  1697. "❤️": ["<3"],
  1698. "😇": ["0:-)"],
  1699. "😂": [":'-)"],
  1700. "😗": [":*"],
  1701. "😐": [":|"],
  1702. "😮": [":-O"],
  1703. "😡": [":@"],
  1704. "🙂": ["😊", ":-)"],
  1705. "😄": [":D"],
  1706. "😭": [";("],
  1707. "😛": [":P"],
  1708. "😅": [",:-)"],
  1709. "😒": [":s"],
  1710. "😉": [";)"],
  1711. "🙃": ["🙂", "😊", "(-:"],
  1712. "🤐": ["🙊", ":secret:"],
  1713. "🕵️": ["👁", ":detective:"],
  1714. }
  1715.  
  1716. var testContext = document.createElement("canvas").getContext('2d');
  1717. function isEmojiAvailable(em) {
  1718. return testContext.measureText(em).width > 8;
  1719. }
  1720.  
  1721. for (var em in compatibleReplacements) {
  1722. if (!isEmojiAvailable(em)) {
  1723. for (var i = 0; i < compatibleReplacements[em].length; i++) {
  1724. if (i == compatibleReplacements[em].length - 1 || isEmojiAvailable(compatibleReplacements[em][i])) {
  1725. wcReplacements[em] = compatibleReplacements[em][i];
  1726. break;
  1727. }
  1728. }
  1729. }
  1730. }
  1731.  
  1732. testContext.canvas.remove();
  1733.  
  1734. if (Object.keys(wcReplacements).length > 0) {
  1735. wcRECompat = new RegExp(Object.keys(wcReplacements).join("|"), "gi");
  1736. wcCompatibleReplace = function (str) {
  1737. return str.replace(wcRECompat, function (matched) {
  1738. return wcReplacements[matched];
  1739. });
  1740. }
  1741. }
  1742. else {
  1743. wcReplacements = null;
  1744. wcCompatibleReplace = function (str) {
  1745. return str;
  1746. };
  1747. }
  1748. }());
  1749.  
  1750. var wcEmoticons = {
  1751. "</3": "💔",
  1752. "<\\\\3": "💔",
  1753. ":-/": "😕",
  1754. ":'-(": "😢",
  1755. ":'(": "😢",
  1756. ":(": "🙁",
  1757. ":-(": "🙁",
  1758. "<3": "❤️",
  1759. "O:-)": "😇",
  1760. "0:-)": "😇",
  1761. "O:)": "😇",
  1762. "0:)": "😇",
  1763. ":'-)": "😂",
  1764. ":')": "😂",
  1765. ":-*": "😗",
  1766. ":*": "😗",
  1767. ":-|": "😐",
  1768. ":|": "😐",
  1769. ":-O": "😮",
  1770. ":O": "😮",
  1771. ":@": "😡",
  1772. ":)": "🙂",
  1773. ":-)": "🙂",
  1774. "=)": "🙂",
  1775. "^^": "😄",
  1776. ":D": "😃",
  1777. ":-D": "😃",
  1778. "=D": "😃",
  1779. "XD": "😆",
  1780. ";(": "😭",
  1781. ":-P": "😛",
  1782. ":P": "😛",
  1783. ",:-)": "😅",
  1784. ":\$": "😒",
  1785. ":S": "😒",
  1786. ";-)": "😉",
  1787. ";)": "😉",
  1788. "(:": "🙃",
  1789. "(-:": "🙃",
  1790. "(=": "🙃",
  1791. ":F": "🐸",
  1792. "(F)": "🐸",
  1793. ":(|)": "🐸"
  1794. }
  1795.  
  1796. var wcEmRe = /(^|\\s)(['\\-\\\$\\(\\)*,/:;@\\\\\\^\\|<=03DOPSXF]{2,4})(\$|\\s)/gi;
  1797.  
  1798. function wcEmoticonsToEmoji(src) {
  1799. wcEmRe.lastIndex = 0;
  1800. var result = "",
  1801. prevIndex = 0,
  1802. REsult;
  1803. while (REsult = wcEmRe.exec(src)) {
  1804. if (REsult[2].toUpperCase() in wcEmoticons) {
  1805. if (REsult[1].length == 1) {
  1806. result += src.substring(prevIndex, REsult.index + 1) + wcEmoticons[REsult[2].toUpperCase()];
  1807. }
  1808. else {
  1809. result += wcEmoticons[REsult[2].toUpperCase()];
  1810. }
  1811.  
  1812. if (REsult[3].length != 0) {
  1813. wcEmRe.lastIndex -= 1;
  1814. }
  1815.  
  1816. prevIndex = wcEmRe.lastIndex;
  1817. }
  1818. else if (REsult[3].length != 0) {
  1819. wcEmRe.lastIndex -= 1;
  1820. }
  1821. }
  1822. result += src.substring(prevIndex);
  1823. return result;
  1824. }
  1825.  
  1826. document.body.addEventListener('keydown', function (e) {
  1827. if (!playingAndReady) return;
  1828. if (e.keyCode == 13) {
  1829. toggleChatInput();
  1830. }
  1831. else if (e.keyCode == 27) {
  1832. hideChatInput()
  1833. }
  1834. else if (e.keyCode == 67) {
  1835. toggleChat();
  1836. }
  1837. })
  1838.  
  1839. chatInput.addEventListener('focusout', function () {
  1840. chatInput.style.visibility = 'hidden';
  1841. });
  1842.  
  1843. chatInput.addEventListener('keydown', function (e) {
  1844. e.stopPropagation();
  1845. if (e.keyCode == 27) {
  1846. hideChatInput();
  1847. }
  1848. else if (e.keyCode == 13) {
  1849. if (chatInput.value.length == 0) {
  1850. hideChatInput();
  1851. }
  1852. else {
  1853. if (wsMsgSendStatus === 0) {
  1854. var message = wcFlags.wcConvertEmoticons ? strToHonkMsg(wcEmoticonsToEmoji(chatInput.value)) : strToHonkMsg(chatInput.value);
  1855. if (typeof (message) == "number") {
  1856. if (message == 0) {
  1857. wcNewNotification("Message length is 0");
  1858. }
  1859. else {
  1860. wcNewNotification(\`Shorten the message by about \${message - 186} characters\`, 5);
  1861. }
  1862. }
  1863. else {
  1864. wcSendMessage(message);
  1865. chatInput.value = "";
  1866. hideChatInput();
  1867. resizeChatInput();
  1868. }
  1869. }
  1870. else {
  1871. wcNewNotification("Please wait...", 2);
  1872. }
  1873. }
  1874. }
  1875. })
  1876.  
  1877. chatInput.addEventListener('keyup', function (e) {
  1878. e.stopPropagation();
  1879. })`
  1880.  
  1881. function waitPageReady(callback) {
  1882. if (typeof(getPlayer) != "function" && typeof(ddEl) != "object") {
  1883. requestAnimationFrame(function(){waitPageReady(callback)});
  1884. }
  1885. else {
  1886. setTimeout(callback,0);
  1887. }
  1888. }
  1889.  
  1890. function addScript() {
  1891. var template = document.createElement('script');
  1892. template.innerHTML = source;
  1893. document.body.appendChild(template);
  1894. }
  1895.  
  1896. waitPageReady(addScript);
  1897.  
  1898. })();