Wrong Chat

Just chat to chat with nearby players

当前为 2020-09-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Wrong Chat
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3.1
  5. // @description Just chat to chat with nearby players
  6. // @author unnamed
  7. // @match http*://splix.io/*
  8. // @grant none
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. "use strict";
  14.  
  15. var source = `"use strict";
  16.  
  17. var wcFlags = {};
  18. var wcFlagList = [
  19. {
  20. "name": "wcConvertEmoticons",
  21. "caption": "Convert emoticons in your messages to emoji",
  22. "description": ":D ⟶ 😄",
  23. "type": "checkbox",
  24. "default": true
  25. },
  26. {
  27. "name": "wcConsoleLog",
  28. "caption": "Print messages to the browser console",
  29. "description": "Until the page is refreshed, you can see the message history in the console.",
  30. "type": "checkbox",
  31. "default": true
  32. },
  33. {
  34. "name": "wcMsgDisplayTime",
  35. "caption": "Message display time",
  36. "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.",
  37. "type": "number",
  38. "default": 90,
  39. "min": 0,
  40. "max": 3600
  41. },
  42. {
  43. "name": "wcMsgDecayTime",
  44. "caption": "Message decay time",
  45. "description": "The time (seconds) during which the messages fade out.<br>It is part of the total display time.",
  46. "type": "number",
  47. "default": 20,
  48. "min": 0,
  49. "max": 3600
  50. },
  51. {
  52. "name": "wcMessageLimit",
  53. "caption": "Number of messages on screen",
  54. "description": "Maximum number of messages displayed on the screen.",
  55. "type": "number",
  56. "default": 20,
  57. "min": 0,
  58. "max": 50
  59. },
  60. {
  61. "name": "wcDefaultNotifications",
  62. "caption": "Show default notifications",
  63. "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.",
  64. "type": "checkbox",
  65. "default": false
  66. },
  67. {
  68. "name": "wcPrivacyWarnings",
  69. "caption": "Enable privacy warnings",
  70. "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.",
  71. "type": "checkbox",
  72. "default": true
  73. },
  74. {
  75. "name": "wcBlockedPlayers",
  76. "caption": "Blocked players",
  77. "description": "List of blocked players in JSON format.<br>Clear the field if you want to clear the list.",
  78. "type": "text",
  79. "default": {}
  80. },
  81. ];
  82.  
  83. (function wcGetFlags() {
  84. for (var i = 0; i < wcFlagList.length; i++) {
  85. var value = localStorage.getItem(wcFlagList[i].name);
  86. if (value !== null) {
  87. if (wcFlagList[i].type == "number") {
  88. value = Number.parseInt(value);
  89. if (Number.isNaN(value)) {
  90. value = wcFlagList[i].default;
  91. }
  92. }
  93. else if (wcFlagList[i].type == "checkbox") {
  94. value = (value == "true");
  95. }
  96. else if (wcFlagList[i].type == "text" && wcFlagList[i].name == "wcBlockedPlayers") {
  97. wcLoadBlockedPlayers();
  98. continue;
  99. }
  100. }
  101. else {
  102. value = wcFlagList[i].default;
  103. }
  104. wcFlags[wcFlagList[i].name] = value;
  105. }
  106. }());
  107.  
  108. if (window.location.pathname == "/flags") {
  109. (function wcFlagListAddControls() {
  110. addHTML('<h4 style="margin-top: 1.5em; margin-bottom: 1em">Wrong Chat Flags</h4>', 'body');
  111. for (var i = 0; i < wcFlagList.length; i++) {
  112. var flag = wcFlagList[i];
  113. var control = \`<label>\${flag.caption}\\t\${flag.name == "wcBlockedPlayers" ? "<br><textarea" : "<input"} name="\${flag.name}" type="\${flag.type}" \${(flag.type == "number") ?
  114. (' style="width: 50px"' + (('min' in flag) ? ' min="' + flag.min + '"' : " ") + (('max' in flag) ? ' max="' + flag.max + '"' : " ") + ' value="' + wcFlags[flag.name] + '"') :
  115. (flag.type == "text" ? (' style="width: 600px; height: 50px"') :
  116. ((flag.type == "checkbox" && wcFlags[flag.name]) ? " checked" : ""))}>\${flag.name == "wcBlockedPlayers" ? "</textarea>" : ""}</label>
  117. <div class="st">\${flag.description}</div>\`;
  118.  
  119. addHTML(control, "body");
  120.  
  121. if (flag.name == "wcBlockedPlayers") {
  122. document.querySelector('textarea[name="wcBlockedPlayers"]').value = JSON.stringify(wcFlags[flag.name]);
  123. }
  124.  
  125. document.querySelector("label:last-of-type input, label:last-of-type textarea").addEventListener("change", function (e) {
  126. if (e.target.type == "number") {
  127. if (!Number.isNaN(e.target.valueAsNumber)) {
  128. localStorage.setItem(e.target.name, e.target.value);
  129. wcFlags[e.target.name] = e.target.valueAsNumber;
  130. }
  131. }
  132. else if (e.target.type == "checkbox") {
  133. localStorage.setItem(e.target.name, e.target.checked);
  134. wcFlags[e.target.name] = e.target.checked;
  135. }
  136. else if (e.target.tagName == "TEXTAREA") {
  137. try {
  138. if (e.target.value.trim() === "") {
  139. localStorage.setItem("wcBlockedPlayers", "{}");
  140. }
  141. else {
  142. var obj = JSON.parse(e.target.value);
  143. localStorage.setItem("wcBlockedPlayers", JSON.stringify(obj));
  144. }
  145. wcLoadBlockedPlayers(false);
  146. }
  147. catch { }
  148. }
  149. });
  150. }
  151. }());
  152. throw new Error("Nobody will read the text of this error"); /** Stop code execution from here */
  153. }
  154.  
  155. 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"]
  156.  
  157. function decToAnyRadixStr(dec, radix = 186, shift = 186) {
  158. let result = "";
  159. if (dec < 0 || dec > 0x10FFFF) return result;
  160. let r;
  161. while (dec > 0) {
  162. r = dec % radix;
  163. dec = ~~(dec / radix);
  164. if (r > 0 || dec > 0) {
  165. result += String.fromCharCode(r + shift); // + shift to avoid interpretation "bytes" as ascii chars
  166. }
  167. }
  168. return result;
  169. }
  170.  
  171. function anyRadixStrToChar(str, radix = 186) {
  172. if (str.length > 3) return "*";
  173. let i, m = 1, result = 0;
  174. for (i = 0; i < str.length; i++) {
  175. result += str.charCodeAt(i) * m;
  176. m *= radix;
  177. }
  178. if (result < 0 || result > 0x10FFFF) return "*";
  179. return String.fromCodePoint(result);
  180. }
  181.  
  182. function wordToSymbols(wordCase, wordSides, wordIndex) {
  183. var control = wordCase * 24 + wordSides * 6 + Math.floor(wordIndex / 186);
  184.  
  185. if (control < 10) { }
  186. else if (control >= 10 && control < 31) {
  187. control += 1
  188. }
  189. else if (control == 31) {
  190. control = 127
  191. }
  192. else if (control > 31 && control < 72) {
  193. control += 96;
  194. }
  195. else {
  196. return "??";
  197. }
  198. return String.fromCharCode(control) + String.fromCharCode(wordIndex % 186 + 186);
  199. }
  200.  
  201. function codesToWord(control, wordCode) {
  202. if (wordCode > 185) {
  203. console.error(\`Bad word code (\${wordCode})\`)
  204. return "<Error>"
  205. }
  206.  
  207. if (control < 10) { }
  208. else if (control >= 11 && control < 32) {
  209. control -= 1
  210. }
  211. else if (control == 127) {
  212. control = 31
  213. }
  214. else if (control > 127 && control < 168) {
  215. control -= 96
  216. }
  217. else {
  218. console.error(\`Bad control code (\${control})\`);
  219. return "<Error>";
  220. }
  221.  
  222. var wordCase = Math.floor(control / 24);
  223. var wordSides = Math.floor((control % 24) / 6);
  224. var wordIndex = (control % 6) * 186 + wordCode;
  225. var word;
  226. if (wordIndex < 1116) {
  227. var word = dict[wordIndex];
  228. }
  229. else {
  230. console.error(\`Unknown word (\${control} \${wordCode})\`)
  231. return "<Error>";
  232. }
  233. return ((wordSides < 2) ? " " : "") +
  234. ((wordCase == 0) ? word : (wordCase == 1 ? word[0].toUpperCase() + word.substring(1) : word.toUpperCase())) +
  235. ((wordSides % 2 == 0) ? " " : "");
  236. }
  237.  
  238. function prepareASCIIString(src) {
  239. var code;
  240. var result = "";
  241. src = src.normalize("NFC");
  242. for (var letter of src) {
  243. code = letter.codePointAt();
  244. if (code == 9) {
  245. result += " ";
  246. }
  247. else if ((code >= 32 && code < 127) || code == 10) {
  248. result += letter;
  249. }
  250. else if (code > 127) {
  251. var base186 = decToAnyRadixStr(code);
  252. result += String.fromCharCode(167 + base186.length) + base186;
  253. }
  254. }
  255. return result;
  256. }
  257.  
  258. function compressWithDict(src) {
  259. var dictWordLength = 0,
  260. dictPosNewLength = 0,
  261. reResult,
  262. re,
  263. srcWord,
  264. srcWordPos,
  265. srcWordLC,
  266. srcWordCase,
  267. srcWordSides,
  268. srcWordLeftSide,
  269. srcWordRightSide,
  270. rSPos,
  271. rEPos,
  272. dictPos = 0,
  273. dictPos2;
  274.  
  275. src = prepareASCIIString(src);
  276.  
  277. while (dictPos < dict.length) {
  278. dictWordLength = dict[dictPos].length;
  279. re = new RegExp(\`['A-Za-z:\\/]{\${dictWordLength}}\`, 'g');
  280.  
  281. while (dictPosNewLength < dict.length && dictWordLength == dict[dictPosNewLength].length) { dictPosNewLength++ }
  282.  
  283. while ((reResult = re.exec(src)) != null) {
  284. srcWord = reResult[0];
  285. srcWordLC = srcWord.toLowerCase();
  286. srcWordPos = reResult.index;
  287. re.lastIndex = srcWordPos + 1;
  288. for (dictPos2 = dictPos; dictPos2 < dictPosNewLength; dictPos2++) {
  289. if (dict[dictPos2] == srcWordLC) {
  290. if (srcWord == srcWordLC) { srcWordCase = 0; }
  291. else if (srcWord == srcWord[0].toUpperCase() + srcWord.substring(1).toLocaleLowerCase()) { srcWordCase = 1; }
  292. else if (srcWord == srcWord.toUpperCase()) { srcWordCase = 2; }
  293. else {
  294. break;
  295. }
  296.  
  297. srcWordLeftSide = src.substring(srcWordPos - 1, srcWordPos);
  298. srcWordRightSide = src.substring(srcWordPos + dictWordLength, srcWordPos + dictWordLength + 1);
  299. if (srcWordLeftSide == " " && srcWordRightSide == " ") { srcWordSides = 0 }
  300. else if (srcWordLeftSide == " ") { srcWordSides = 1 }
  301. else if (srcWordRightSide == " ") { srcWordSides = 2 }
  302. else if (dictWordLength > 2) { srcWordSides = 3 }
  303. else {
  304. break;
  305. }
  306.  
  307. rSPos = srcWordSides < 2 ? srcWordPos - 1 : srcWordPos;
  308. rEPos = (srcWordSides % 2 == 0) ? srcWordPos + dictWordLength + 1 : srcWordPos + dictWordLength;
  309. src = src.substring(0, rSPos) + wordToSymbols(srcWordCase, srcWordSides, dictPos2) + src.substring(rEPos);
  310.  
  311. if (srcWordSides > 1) { re.lastIndex = srcWordPos + 2; }
  312. break;
  313. }
  314. }
  315. }
  316. dictPos = dictPosNewLength;
  317. }
  318.  
  319. let result = "";
  320. let code;
  321. for (var i = 0; i < src.length; i++) {
  322. code = src.charCodeAt(i);
  323. if (code >= 186) {
  324. result += String.fromCharCode(code - 186);
  325. }
  326. else {
  327. result += src[i];
  328. }
  329. }
  330. return result;
  331. }
  332.  
  333. function decompressWithDict(src) {
  334. var result = "",
  335. i = 0,
  336. code;
  337. while (i < src.length) {
  338. code = src.codePointAt(i);
  339. if ((code > 31 && code < 127) || code == 10) {
  340. result += src[i];
  341. i += 1;
  342. }
  343. else if (code > 167 && code <= 170) {
  344. code -= 167;
  345. result += anyRadixStrToChar(src.substring(i + 1, i + 1 + code));
  346. i += 1 + code;
  347. }
  348. else if (code > 170) {
  349. console.error(\`decompressASCII: bad code (\${code})\`);
  350. return result + " ... <Error>";
  351. }
  352. else {
  353. result += codesToWord(code, src.codePointAt(i + 1));
  354. i += 2;
  355. }
  356. }
  357. return result;
  358. }
  359.  
  360. /**
  361. * SCSU - Standard Compression Scheme for Unicode implementation for JavaScript
  362. *
  363. * Provides SCSU encoding/decoding of UTF-8 strings
  364. * Suitable for better LZF compression for UTF-8 strings
  365. * Based on Java source of SCSU by Unicode, Inc. (http:
  366. *
  367. * @class Provides methods for SCSU encoding/decoding
  368. * @author Alexey A.Znaev (znaeff@mail.ru) (http:
  369. * @copyright Copyright (C) 2011-2012 Alexey A.Znaev
  370. * @license http:
  371. * @version 1.0
  372. */
  373. function SCSU() { }
  374.  
  375. SCSU.prototype._SQ0 = 0x01;
  376. SCSU.prototype._SQ1 = 0x02;
  377. SCSU.prototype._SQ2 = 0x03;
  378. SCSU.prototype._SQ3 = 0x04;
  379. SCSU.prototype._SQ4 = 0x05;
  380. SCSU.prototype._SQ5 = 0x06;
  381. SCSU.prototype._SQ6 = 0x07;
  382. SCSU.prototype._SQ7 = 0x08;
  383.  
  384. SCSU.prototype._SDX = 0x0B;
  385. SCSU.prototype._Srs = 0x0C;
  386.  
  387. SCSU.prototype._SQU = 0x0E;
  388. SCSU.prototype._SCU = 0x0F;
  389.  
  390. SCSU.prototype._SC0 = 0x10;
  391. SCSU.prototype._SC1 = 0x11;
  392. SCSU.prototype._SC2 = 0x12;
  393. SCSU.prototype._SC3 = 0x13;
  394. SCSU.prototype._SC4 = 0x14;
  395. SCSU.prototype._SC5 = 0x15;
  396. SCSU.prototype._SC6 = 0x16;
  397. SCSU.prototype._SC7 = 0x17;
  398. SCSU.prototype._SD0 = 0x18;
  399. SCSU.prototype._SD1 = 0x19;
  400. SCSU.prototype._SD2 = 0x1A;
  401. SCSU.prototype._SD3 = 0x1B;
  402. SCSU.prototype._SD4 = 0x1C;
  403. SCSU.prototype._SD5 = 0x1D;
  404. SCSU.prototype._SD6 = 0x1E;
  405. SCSU.prototype._SD7 = 0x1F;
  406.  
  407. SCSU.prototype._UC0 = 0xE0;
  408. SCSU.prototype._UC1 = 0xE1;
  409. SCSU.prototype._UC2 = 0xE2;
  410. SCSU.prototype._UC3 = 0xE3;
  411. SCSU.prototype._UC4 = 0xE4;
  412. SCSU.prototype._UC5 = 0xE5;
  413. SCSU.prototype._UC6 = 0xE6;
  414. SCSU.prototype._UC7 = 0xE7;
  415. SCSU.prototype._UD0 = 0xE8;
  416. SCSU.prototype._UD1 = 0xE9;
  417. SCSU.prototype._UD2 = 0xEA;
  418. SCSU.prototype._UD3 = 0xEB;
  419. SCSU.prototype._UD4 = 0xEC;
  420. SCSU.prototype._UD5 = 0xED;
  421. SCSU.prototype._UD6 = 0xEE;
  422. SCSU.prototype._UD7 = 0xEF;
  423.  
  424. SCSU.prototype._UQU = 0xF0;
  425. SCSU.prototype._UDX = 0xF1;
  426. SCSU.prototype._Urs = 0xF2;
  427.  
  428. SCSU.prototype._gapThreshold = 0x68;
  429. SCSU.prototype._gapOffset = 0xAC00;
  430.  
  431. SCSU.prototype._reservedStart = 0xA8;
  432. SCSU.prototype._fixedThreshold = 0xF9;
  433.  
  434. SCSU.prototype._fixedOffset = [0x00C0, 0x0250, 0x0370, 0x0530, 0x3040, 0x30A0, 0xFF60];
  435.  
  436. SCSU.prototype._staticOffset = [0x0000, 0x0080, 0x0100, 0x0300, 0x2000, 0x2080, 0x2100, 0x3000];
  437.  
  438. SCSU.prototype._initialDynamicOffset = [0x0080, 0x00C0, 0x0400, 0x0600, 0x0900, 0x3040, 0x30A0, 0xFF00];
  439.  
  440. /**
  441. * Encodes UTF-8 string using SCSU algorithm
  442. *
  443. * @param {String} str UTF-8 string
  444. * @return {String} SCSU-encoded string
  445. * @throws {SCSUError}
  446. */
  447. SCSU.prototype.compress = function (str) {
  448. var iLen = 0, ch, ch2, iprevWindow;
  449. this._reset();
  450. this.sIn = str;
  451. this.iInLen = str.length;
  452. this.aOut = [];
  453. while (this.iIn < this.iInLen) {
  454. if (this.iSCU != -1) {
  455. ch = this._outputUnicodeRun();
  456. if (this.aOut.length - this.iSCU == 3) {
  457. this.aOut[this.iSCU] = this._SQU;
  458. this.iSCU = -1;
  459. continue;
  460. } else {
  461. this.iSCU = -1;
  462. this.fUnicodeMode = true;
  463. }
  464. } else ch = this._outputSingleByteRun();
  465. if (this.iIn == this.iInLen) break;
  466. for (var ich = this.iIn; ch < 0x80; ich++) {
  467. if (ich == this.iInLen || !this._isCompressible(this.sIn.charCodeAt(ich))) {
  468. ch = this.sIn.charCodeAt(this.iIn);
  469. break;
  470. }
  471. ch = this.sIn.charCodeAt(ich);
  472. }
  473. iprevWindow = this.iSelectedWindow;
  474. if (ch < 0x80 || this._locateWindow(ch, this.dynamicOffset)) {
  475. if (!this.fUnicodeMode && this.iIn < this.iInLen - 1) {
  476. ch2 = this.sIn.charCodeAt(this.iIn + 1);
  477. if (ch2 >= this.dynamicOffset[iprevWindow] && ch2 < this.dynamicOffset[iprevWindow] + 0x80) {
  478. this._quoteSingleByte(ch);
  479. this.iSelectedWindow = iprevWindow;
  480. continue;
  481. }
  482. }
  483. this.aOut.push(((this.fUnicodeMode ? this._UC0 : this._SC0) + this.iSelectedWindow) & 255);
  484. this.fUnicodeMode = false;
  485. } else if (!this.fUnicodeMode && this._locateWindow(ch, this._staticOffset)) {
  486. this._quoteSingleByte(ch);
  487. this.iSelectedWindow = iprevWindow;
  488. continue;
  489. } else if (this._positionWindow(ch)) {
  490. this.fUnicodeMode = false;
  491. } else {
  492. this.iSCU = this.aOut.length;
  493. this.aOut.push(this._SCU);
  494. continue;
  495. }
  496. }
  497. delete this.sIn;
  498. var a_out_symbols = [];
  499. for (var i = 0; i < this.aOut.length; i++) a_out_symbols.push(String.fromCharCode(this.aOut[i]));
  500. delete this.aOut;
  501. return a_out_symbols.join('');
  502. }
  503.  
  504. /**
  505. * Decodes SCSU-encoded string to UTF-8 one
  506. *
  507. * @param {String} str SCSU-encoded string
  508. * @return {String} UTF-8 string
  509. * @throws {SCSUError}
  510. */
  511. SCSU.prototype.decompress = function (str) {
  512. this._reset();
  513. this.sIn = str;
  514. this.iInLen = str.length;
  515. var sOut = '';
  516. var iStaticWindow, iDynamicWindow, ch;
  517. Loop:
  518. for (var iCur = 0; iCur < this.iInLen; iCur++) {
  519. iStaticWindow = 0;
  520. iDynamicWindow = this.iSelectedWindow;
  521. Switch:
  522. switch (this.sIn.charCodeAt(iCur)) {
  523. case this._SQ0:
  524. case this._SQ1:
  525. case this._SQ2:
  526. case this._SQ3:
  527. case this._SQ4:
  528. case this._SQ5:
  529. case this._SQ6:
  530. case this._SQ7:
  531. if (iCur >= this.iInLen - 1) break Loop;
  532. iDynamicWindow = iStaticWindow = this.sIn.charCodeAt(iCur) - this._SQ0;
  533. iCur++;
  534. default:
  535. if (this.sIn.charCodeAt(iCur) < 128) {
  536. ch = this.sIn.charCodeAt(iCur) + this._staticOffset[iStaticWindow];
  537. sOut += String.fromCharCode(ch);
  538. } else {
  539. ch = this.sIn.charCodeAt(iCur);
  540. ch -= 0x80;
  541. ch += this.dynamicOffset[iDynamicWindow];
  542. if (ch < 1 << 16) {
  543. sOut += String.fromCharCode(ch);
  544. } else {
  545. ch -= 0x10000;
  546. sOut += String.fromCharCode(0xD800 + (ch >> 10));
  547. sOut += String.fromCharCode(0xDC00 + (ch & ~0xFC00));
  548. }
  549. }
  550. break;
  551. case this._SDX:
  552. iCur += 2;
  553. if (iCur >= this.iInLen) break Loop;
  554. this._defineExtendedWindow(this._charFromTwoBytes(aIn[iCur - 1], this.sIn.charCodeAt(iCur)));
  555. break;
  556. case this._SD0:
  557. case this._SD1:
  558. case this._SD2:
  559. case this._SD3:
  560. case this._SD4:
  561. case this._SD5:
  562. case this._SD6:
  563. case this._SD7:
  564. iCur++;
  565. if (iCur >= this.iInLen) break Loop;
  566. this._defineWindow(this.sIn.charCodeAt(iCur - 1) - this._SD0, this.sIn.charCodeAt(iCur));
  567. break;
  568. case this._SC0:
  569. case this._SC1:
  570. case this._SC2:
  571. case this._SC3:
  572. case this._SC4:
  573. case this._SC5:
  574. case this._SC6:
  575. case this._SC7:
  576. this.iSelectedWindow = this.sIn.charCodeAt(iCur) - this._SC0;
  577. break;
  578. case this._SCU:
  579. iCur++;
  580. for (var b; iCur < this.iInLen - 1; iCur += 2) {
  581. b = this.sIn.charCodeAt(iCur);
  582. if (b >= this._UC0 && b <= this._UC7) {
  583. this.iSelectedWindow = b - this._UC0;
  584. break Switch;
  585. } else if (b >= this._UD0 && b <= this._UD7) {
  586. this._defineWindow(b - this._UD0, this.sIn.charCodeAt(iCur + 1));
  587. iCur++;
  588. break Switch;
  589. } else if (b == this._UDX) {
  590. this._defineExtendedWindow(this._charFromTwoBytes(this.sIn.charCodeAt(iCur + 1), this.sIn.charCodeAt(iCur + 2)));
  591. iCur += 2;
  592. break Switch;
  593. } else if (b == this._UQU) {
  594. iCur++;
  595. }
  596. sOut += String.fromCharCode(this._charFromTwoBytes(this.sIn.charCodeAt(iCur), this.sIn.charCodeAt(iCur + 1)));
  597. }
  598. if (iCur != this.iInLen) throw new SCSUError(this._errorText(0x11));
  599. break;
  600. case this._SQU:
  601. iCur += 2;
  602. if (iCur >= this.iInLen) {
  603. break Loop;
  604. } else {
  605. ch = this._charFromTwoBytes(this.sIn.charCodeAt(iCur - 1), this.sIn.charCodeAt(iCur));
  606. sOut += String.fromCharCode(ch);
  607. }
  608. break;
  609. case this._Srs:
  610. throw new SCSUError(this._errorText(0x16, 'Pos. ' + iCur + '.'));
  611. }
  612. }
  613. delete this.sIn;
  614. if (iCur < this.iInLen) throw new SCSUError(this._errorText(0x11));
  615. return sOut;
  616. }
  617.  
  618. SCSU.prototype._isCompressible = function (ch) {
  619. return (ch < 0x3400 || ch >= 0xE000);
  620. }
  621.  
  622. SCSU.prototype._reset = function () {
  623. this.iIn = 0;
  624. this.iSelectedWindow = 0;
  625. this.dynamicOffset = this._initialDynamicOffset.slice(0);
  626. this.iSCU = -1;
  627. this.fUnicodeMode = false;
  628. this.iNextWindow = 3;
  629. }
  630.  
  631. SCSU.prototype._locateWindow = function (ch, offsetTable) {
  632. var iWin = this.iSelectedWindow;
  633. if (iWin != - 1 && ch >= offsetTable[iWin] && ch < offsetTable[iWin] + 0x80) return true;
  634. for (iWin = 0; iWin < offsetTable.length; iWin++) {
  635. if (ch >= offsetTable[iWin] && ch < offsetTable[iWin] + 0x80) {
  636. this.iSelectedWindow = iWin;
  637. return true;
  638. }
  639. }
  640. return false;
  641. }
  642.  
  643. SCSU.prototype._isAsciiCrLfOrTab = function (ch) {
  644. return (ch >= 0x20 && ch <= 0x7F) || ch == 0x09 || ch == 0x0A || ch == 0x0D;
  645. }
  646.  
  647. SCSU.prototype._outputSingleByteRun = function () {
  648. var iWin = this.iSelectedWindow, ch, ch2, byte1, byte2, aInLen;
  649. while (this.iIn < this.iInLen) {
  650. this.iOutLen = 0;
  651. byte1 = 0;
  652. byte2 = 0;
  653. ch = this.sIn.charCodeAt(this.iIn);
  654. aInLen = 1;
  655. if ((ch & 0xF800) == 0xD800) {
  656. if ((ch & 0xFC00) == 0xDC00) {
  657. throw new SCSUError(this._errorText(0x12, 'Byte #' + this.iIn + '.'));
  658. } else {
  659. if (this.iIn >= this.iInLen - 1) throw new SCSUError(this._errorText(0x11));
  660. ch2 = this.sIn.charCodeAt(this.iIn + 1);
  661. if ((ch2 & 0xFC00) != 0xDC00) throw new SCSUError(this._errorText(0x13, 'Byte #' + (this.iIn + 1) + '.'));
  662. ch = ((ch - 0xD800) << 10 | (ch2 - 0xDC00)) + 0x10000;
  663. aInLen = 2;
  664. }
  665. }
  666. if (this._isAsciiCrLfOrTab(ch) || ch == 0) {
  667. byte2 = ch & 0x7F;
  668. this.iOutLen = 1;
  669. } else if (ch < 0x20) {
  670. byte1 = this._SQ0;
  671. byte2 = ch;
  672. this.iOutLen = 2;
  673. } else if (ch >= this.dynamicOffset[iWin] && ch < this.dynamicOffset[iWin] + 0x80) {
  674. ch -= this.dynamicOffset[iWin];
  675. byte2 = (ch | 0x80) & 255;
  676. this.iOutLen = 1;
  677. }
  678. switch (this.iOutLen) {
  679. default:
  680. return ch;
  681. case 2:
  682. this.aOut.push(byte1);
  683. case 1:
  684. this.aOut.push(byte2);
  685. break;
  686. }
  687. this.iIn += aInLen;
  688. }
  689. return 0;
  690. }
  691.  
  692. SCSU.prototype._quoteSingleByte = function (ch) {
  693. var iWin = this.iSelectedWindow, ch;
  694. this.aOut.push((this._SQ0 + iWin) & 255);
  695. if (ch >= this.dynamicOffset[iWin] && ch < this.dynamicOffset[iWin] + 0x80) {
  696. ch -= this.dynamicOffset[iWin];
  697. this.aOut.push((ch | 0x80) & 255);
  698. } else if (ch >= this._staticOffset[iWin] && ch < this._staticOffset[iWin] + 0x80) {
  699. ch -= this._staticOffset[iWin];
  700. this.aOut.push(ch & 255);
  701. } else throw new SCSUError(this._errorText(0x00, 'ch = ' + ch + ' not valid in _quoteSingleByte.'));
  702. this.iIn++;
  703. }
  704.  
  705. SCSU.prototype._outputUnicodeRun = function () {
  706. var ch = 0, ch2;
  707. while (this.iIn < this.iInLen) {
  708. ch = this.sIn.charCodeAt(this.iIn);
  709. this.iOutLen = 2;
  710. if (this._isCompressible(ch)) {
  711. if (this.iIn < this.iInLen - 1) {
  712. ch2 = this.sIn.charCodeAt(this.iIn + 1);
  713. if (this._isCompressible(ch2)) break;
  714. }
  715. if (ch >= 0xE000 && ch <= 0xF2FF) this.iOutLen = 3;
  716. }
  717. if (this.iOutLen == 3) this.aOut.push(this._UQU);
  718. this.aOut.push((ch >> 8) & 255);
  719. this.aOut.push(ch & 0xFF);
  720. this.iIn++;
  721. }
  722. return ch;
  723. }
  724.  
  725. SCSU.prototype._positionWindow = function (ch) {
  726. var iWin = this.iNextWindow % 8, iPosition = 0, ch;
  727. if (ch < 0x80) throw new SCSUError(this._errorText(0x00, 'ch < 0x80.'));
  728. for (var i = 0; i < this._fixedOffset.length; i++) {
  729. if (ch >= this._fixedOffset[i] && ch < this._fixedOffset[i] + 0x80) {
  730. iPosition = i;
  731. break;
  732. }
  733. }
  734. if (iPosition != 0) {
  735. this.dynamicOffset[iWin] = this._fixedOffset[iPosition];
  736. iPosition += 0xF9;
  737. } else if (ch < 0x3400) {
  738. iPosition = ch >> 7;
  739. this.dynamicOffset[iWin] = ch & 0xFF80;
  740. } else if (ch < 0xE000) {
  741. return false;
  742. } else if (ch <= 0xFFFF) {
  743. iPosition = ((ch - this._gapOffset) >> 7);
  744. this.dynamicOffset[iWin] = ch & 0xFF80;
  745. } else {
  746. iPosition = (ch - 0x10000) >> 7;
  747. iPosition |= iWin << 13;
  748. this.dynamicOffset[iWin] = ch & 0x1FFF80;
  749. }
  750. if (iPosition < 0x100) {
  751. this.aOut.push(((this.fUnicodeMode ? this._UD0 : this._SD0) + iWin) & 255);
  752. this.aOut.push(iPosition & 0xFF);
  753. } else if (iPosition >= 0x100) {
  754. this.aOut.push(this.fUnicodeMode ? this._UDX : this._SDX);
  755. this.aOut.push((iPosition >> 8) & 0xFF);
  756. this.aOut.push(iPosition & 0xFF);
  757. }
  758. this.iSelectedWindow = iWin;
  759. this.iNextWindow++;
  760. return true;
  761. }
  762.  
  763. SCSU.prototype._defineWindow = function (iWin, bOffset) {
  764. var iOffset = (bOffset < 0 ? bOffset + 256 : bOffset);
  765. if (iOffset == 0) {
  766. throw new SCSUError(this._errorText(0x14));
  767. } else if (iOffset < this._gapThreshold) {
  768. this.dynamicOffset[iWin] = iOffset << 7;
  769. } else if (iOffset < this._reservedStart) {
  770. this.dynamicOffset[iWin] = (iOffset << 7) + this._gapOffset;
  771. } else if (iOffset < this._fixedThreshold) {
  772. throw new SCSUError(this._errorText(0x15, 'Value = ' + iOffset + '.'));
  773. } else {
  774. this.dynamicOffset[iWin] = this._fixedOffset[iOffset - this._fixedThreshold];
  775. }
  776. this.iSelectedWindow = iWin;
  777. }
  778.  
  779. SCSU.prototype._defineExtendedWindow = function (chOffset) {
  780. var iWin = chOffset >> 13;
  781. this.dynamicOffset[iWin] = ((chOffset & 0x1FFF) << 7) + (1 << 16);
  782. this.iSelectedWindow = iWin;
  783. }
  784.  
  785. SCSU.prototype._charFromTwoBytes = function (hi, lo) {
  786. var ch = (lo >= 0 ? lo : 256 + lo);
  787. return (ch + ((hi >= 0 ? hi : 256 + hi) << 8));
  788. }
  789.  
  790. SCSU.prototype._ERRORS = {
  791. 0x00: 'Internal error.',
  792. 0x10: 'Illegal input.',
  793. 0x11: 'Ended prematurely.',
  794. 0x12: 'Unpaired low surrogate.',
  795. 0x13: 'Unpaired high surrogate.',
  796. 0x14: 'Zero offset.',
  797. 0x15: 'Bad offset.',
  798. 0x16: 'Srs byte found.',
  799. 0x20: 'Bad output.'
  800. };
  801.  
  802. SCSU.prototype._errorText = function (code, text) {
  803. if (code == null || (typeof code != 'number') || code < 0 || code > 0xFF) code = 0x00;
  804. if (text == null || (typeof text != 'string')) text = '';
  805. var message = '';
  806. var code_class = code & 0xF0;
  807. if (this._ERRORS[code_class]) message = this._ERRORS[code_class];
  808. if ((code != code_class) && this._ERRORS[code]) message += ' ' + this._ERRORS[code];
  809. return ('SCSU 0x' + code.toString(16) + ': ' + message + (text == '' ? '' : ' ') + text);
  810. }
  811.  
  812. /**
  813. * SCSU Errors exceptions
  814. *
  815. * @class Constructs exceptions of SCSU errors
  816. * @author Alexey A.Znaev (znaeff@mail.ru) (http:
  817. * @copyright Copyright (C) 2011-2012 Alexey A.Znaev
  818. * @license http:
  819. * @version 1.0
  820. */
  821. function SCSUError(msg) { this.message = msg; this.name = 'SCSUError' };
  822. SCSUError.prototype = new Error();
  823.  
  824. function removeControlASCIISymbols(str) {
  825. var code;
  826. var result = "";
  827. for (var i = 0; i < str.length; i++) {
  828. code = str.codePointAt(i);
  829. if (code == 9) {
  830. result += " ";
  831. }
  832. else if ((code >= 32 && code < 127) || code > 127 || code == 10) {
  833. result += str[i]
  834. }
  835. }
  836. return result;
  837. }
  838.  
  839. function compressWithSCSU(src) {
  840. src = removeControlASCIISymbols(src);
  841. var result;
  842. try {
  843. result = SCSU.prototype.compress(src);
  844. }
  845. catch (e) {
  846. console.error("SCSU compression error:", e);
  847. return null;
  848. }
  849. return result;
  850. }
  851.  
  852. function decompressWithSCSU(src) {
  853. var result;
  854. try {
  855. result = SCSU.prototype.decompress(src);
  856. }
  857. catch (e) {
  858. //console.error("SCSU decompression error:", e);
  859. return null;
  860. }
  861. return result;
  862. }
  863.  
  864. function unicodeToRadix183Str(src) {
  865. var result = "",
  866. code;
  867. for (var letter of src) {
  868. code = letter.codePointAt();
  869. if (code < 183) {
  870. result += letter;
  871. }
  872. else if (code > 127) {
  873. var base183 = decToAnyRadixStr(code, 183, 0);
  874. result += String.fromCharCode(182 + base183.length) + base183;
  875. }
  876. }
  877. return result;
  878. }
  879.  
  880. function radix183StrToUnicode(src) {
  881. var result = "",
  882. i = 0,
  883. code;
  884. while (i < src.length) {
  885. code = src.codePointAt(i);
  886. if (code < 183) {
  887. result += src[i];
  888. i += 1;
  889. }
  890. else {
  891. code -= 182;
  892. result += anyRadixStrToChar(src.substring(i + 1, i + 1 + code), 183, 0);
  893. i += 1 + code;
  894. }
  895. }
  896. return result;
  897. }
  898.  
  899. function strToHonkMsg(src) {
  900. var encodingType,
  901. result;
  902.  
  903. if (src.length == 0) {
  904. encodingType = 3;
  905. result = " ";
  906. }
  907. else {
  908. var codedWithDict = compressWithDict(src);
  909. var codedWithoutDict = compressWithSCSU(src);
  910.  
  911. var scsu = false;
  912. if (codedWithoutDict !== null) {
  913. if (decompressWithSCSU(codedWithoutDict) !== null) {
  914. codedWithoutDict = unicodeToRadix183Str(codedWithoutDict);
  915. scsu = true;
  916. }
  917. }
  918.  
  919. if (!scsu) {
  920. codedWithoutDict = unicodeToRadix183Str(src);
  921. }
  922.  
  923. if (codedWithDict.length < codedWithoutDict.length) {
  924. result = codedWithDict;
  925. encodingType = 1;
  926. }
  927. else {
  928. result = codedWithoutDict;
  929. encodingType = scsu ? 2 : 3;
  930. }
  931. }
  932.  
  933. if (result.length > 186 || result.length < 1) {
  934. return result.length;
  935. }
  936. else {
  937. return String.fromCharCode(encodingType) + String.fromCharCode(result.length - 1) + result;
  938. }
  939. }
  940.  
  941. function honkMsgToString(src) {
  942. const errMsg = "<Decoding error>";
  943. var srcLen = src.length,
  944. result = "";
  945. if (srcLen < 3 || srcLen > 186 + 2) {
  946. console.error(\`honkMsgToString: incorrect length of source (\${src.length})\`);
  947. return errMsg;
  948. }
  949. else {
  950. var encodingType = src.codePointAt(0);
  951. if (encodingType < 1 || encodingType > 3) {
  952. console.error(\`honkMsgToString: incorrect encoding type (\${encodingType})\`);
  953. return errMsg;
  954. }
  955.  
  956. var textLen = src.codePointAt(1);
  957. if (srcLen - 2 != textLen) {
  958. console.error(\`honkMsgToString: incorrect message text length (\${srcLen} / \${textLen})\`);
  959. return errMsg;
  960. }
  961.  
  962. try {
  963. if (encodingType == 1) {
  964. result = decompressWithDict(src.substring(2));
  965. }
  966. else if (encodingType == 2) {
  967. result = decompressWithSCSU(radix183StrToUnicode(src.substring(2)));
  968. }
  969. else if (encodingType == 3) {
  970. result = radix183StrToUnicode(src.substring(2));
  971. }
  972.  
  973. return result.replace(/(\\r\\n|\\r|\\n){2,}/g, '\$1\\n');
  974. }
  975. catch (e) {
  976. console.error(\`honkMsgToString: decompression error (type \${encodingType})\`, e);
  977. return errMsg;
  978. }
  979. }
  980. }
  981.  
  982. var wcMessage = "";
  983. var wcMessagePos = 0;
  984.  
  985. function wcSendMsgHonk() {
  986. var code = wcMessage.charCodeAt(wcMessagePos) + 70;
  987. wcMessagePos += 1;
  988. wsSendMsg(sendAction.HONK, code);
  989. players[0].doHonk(code);
  990. if (wcMessagePos < wcMessage.length) {
  991. setTimeout(wcSendMsgHonk, ((wcMessagePos < 13e0) ? 50e0 : ((wcMessagePos < 26e0) ? 65e0 : 85e0)));
  992. }
  993. else {
  994. wsMsgSendStatus = 0;
  995. }
  996. }
  997.  
  998. function wcSendMessage(message) {
  999. wcMessage = String.fromCharCode(1) + String.fromCharCode(57) + message;
  1000. wcMessagePos = 0;
  1001. wsMsgSendStatus = 1;
  1002. wcSendMsgHonk();
  1003. }
  1004.  
  1005. function wcMsgHonkHandler(player, value) {
  1006. if (player.msgStatus == 0) {
  1007. if (value == 71 && !wcIsPlayerBlocked(player.name, player.skinBlock)) {
  1008. player.msgStatus = 1;
  1009. }
  1010. else return;
  1011. }
  1012. else if (player.msgStatus == 1) {
  1013. if (value == 127) {
  1014. player.msgStatus = 2;
  1015. }
  1016. else {
  1017. player.msgStatus = 0;
  1018. }
  1019. }
  1020. else if (player.msgStatus == 2) {
  1021. if (value >= 71 && value <= 73) {
  1022. player.msgStatus = 3;
  1023. player.message = String.fromCharCode(value - 70);
  1024. }
  1025. else {
  1026. player.msgStatus = 0;
  1027. }
  1028. }
  1029. else if (player.msgStatus == 3) {
  1030. player.msgStatus = 4;
  1031. player.msgLength = value - 69 + 2;
  1032. player.message += String.fromCharCode(value - 69);
  1033. }
  1034. else {
  1035. player.message += String.fromCharCode(value - 70);
  1036. if (player.message.length >= player.msgLength) {
  1037. wcNewMessage(player.message, player.name, player.skinBlock);
  1038. player.msgStatus = 0;
  1039. }
  1040. }
  1041. }
  1042.  
  1043. function honkEndWC() {
  1044. if (wsMsgSendStatus === 0) {
  1045. var e = Date.now();
  1046. if (lastHonkTime < e) {
  1047. var t = clamp(t = e - honkStartTime, 0, 1e3);
  1048. lastHonkTime = e + t,
  1049. t = iLerp(0, 1e3, t),
  1050. t *= 255,
  1051. t = Math.floor(t),
  1052. wsSendMsg(sendAction.HONK, t);
  1053. for (var n = 0; n < players.length; n++) {
  1054. var a = players[n];
  1055. a.isMyPlayer && a.doHonk(Math.max(70, t))
  1056. }
  1057. }
  1058. }
  1059. }
  1060.  
  1061. function getPlayerWC(e, t) {
  1062. var n;
  1063. void 0 === t && (t = players);
  1064. for (var a = 0; a < t.length; a++)
  1065. if ((n = t[a]).id == e)
  1066. return n;
  1067. return n = {
  1068. id: e,
  1069. pos: [0, 0],
  1070. drawPos: [-1, -1],
  1071. drawPosSet: !1,
  1072. serverPos: [0, 0],
  1073. dir: 0,
  1074. isMyPlayer: 0 === e,
  1075. isDead: !1,
  1076. deathWasCertain: !1,
  1077. didUncertainDeathLastTick: !1,
  1078. isDeadTimer: 0,
  1079. uncertainDeathPosition: [0, 0],
  1080. message: "",
  1081. msgStatus: 0,
  1082. msgLength: 0,
  1083. die: function (e) {
  1084. if (e = !!e, this.isDead)
  1085. this.deathWasCertain = e || this.deathWasCertain;
  1086. else if (e || !this.didUncertainDeathLastTick) {
  1087. e || (this.didUncertainDeathLastTick = !0, this.uncertainDeathPosition = [this.pos[0], this.pos[1]]),
  1088. this.isDead = !0,
  1089. this.deathWasCertain = e,
  1090. this.deadAnimParts = [0],
  1091. this.isDeadTimer = 0,
  1092. this.isMyPlayer && doCamShakeDir(this.dir);
  1093. for (var t = 0; ;) {
  1094. if ((t += .4 * Math.random() + .5) >= 2 * Math.PI) {
  1095. this.deadAnimParts.push(2 * Math.PI);
  1096. break
  1097. }
  1098. this.deadAnimParts.push(t),
  1099. this.deadAnimPartsRandDist.push(Math.random())
  1100. }
  1101. }
  1102. },
  1103. undoDie: function () {
  1104. this.isDead = !1
  1105. },
  1106. deadAnimParts: [],
  1107. deadAnimPartsRandDist: [],
  1108. addHitLine: function (e, t) {
  1109. this.hitLines.push({
  1110. pos: e,
  1111. vanishTimer: 0,
  1112. color: t
  1113. })
  1114. },
  1115. hitLines: [],
  1116. doHonk: function (e) {
  1117. this.honkTimer = 0,
  1118. this.honkMaxTime = e,
  1119. "joris" == this.name.toLowerCase() && (null == honkSfx && (honkSfx = new Audio("/honk.mp3")), honkSfx.play());
  1120. wcMsgHonkHandler(this, e);
  1121. },
  1122. moveRelativeToServerPosNextFrame: !1,
  1123. lastServerPosSentTime: 0,
  1124. honkTimer: 0,
  1125. honkMaxTime: 0,
  1126. trails: [],
  1127. name: "",
  1128. skinBlock: 0,
  1129. lastBlock: null,
  1130. hasReceivedPosition: !1
  1131. },
  1132. t.push(n),
  1133. n.isMyPlayer && (myPlayer = n),
  1134. n
  1135. }
  1136.  
  1137. getPlayer = getPlayerWC;
  1138. honkEnd = honkEndWC;
  1139.  
  1140. var style = \`
  1141. #chatbox {
  1142. position: absolute;
  1143. right: 0;
  1144. bottom: 0;
  1145. }
  1146.  
  1147. #chatbox > * {
  1148. clear:both;
  1149. float:right;
  1150. }
  1151.  
  1152. #chatMessages > * {
  1153. clear:both;
  1154. float:right;
  1155. }
  1156.  
  1157. #chatNotifications > * {
  1158. clear:both;
  1159. float:right;
  1160. }
  1161.  
  1162. .chatMessage, .chatNotification {
  1163. display: flex;
  1164. background: #2d2824;
  1165. border: solid 2px #332d29;
  1166. margin: 1px 7px;
  1167. border-radius: 9px;
  1168. overflow: hidden;
  1169. max-width: 450px;
  1170. user-select: text;
  1171. opacity: 1;
  1172. }
  1173.  
  1174. .chatNotification {
  1175. max-height: 100px;
  1176. }
  1177.  
  1178. .chatNotification > span {
  1179. color: #fff;
  1180. font-style: italic;
  1181. display: flex;
  1182. align-items: center;
  1183. padding: 4px 10px;
  1184. }
  1185.  
  1186. #chatInput {
  1187. display: inline-block;
  1188. background: #7a6d62;
  1189. color: #000000;
  1190. border: solid 4px #3a342f;
  1191. margin: 1px 0 0 0;
  1192. padding: 0 0.2em;
  1193. font-size: 1.1em;
  1194. line-height: 1.4em;
  1195. outline: none;
  1196. min-width: 250px;
  1197. font-family: "Lucida Console", Monaco, monospace;
  1198. visibility: hidden;
  1199. }
  1200.  
  1201. .chatMessage > span {
  1202. display: flex;
  1203. align-items: center;
  1204. padding-top: 4px;
  1205. padding-bottom: 4px;
  1206. }
  1207.  
  1208. .chatMessage span:last-of-type{
  1209. color: #fff;
  1210. background: #413a35;
  1211. padding-left: 10px;
  1212. padding-right: 10px;
  1213. overflow-wrap: anywhere;
  1214. }
  1215.  
  1216. .chatMessage span:first-of-type{
  1217. color: #ffffff80;
  1218. font-weight: bold;
  1219. padding-left: 5px;
  1220. padding-right: 5px;
  1221. cursor: pointer;
  1222. }
  1223.  
  1224. #wcBlock {
  1225. position: absolute;
  1226. min-width: 300px;
  1227. background: #4d453e;
  1228. border: solid 1px #000000;
  1229. color: #ffffff;
  1230. text-align: center;
  1231. box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.1);
  1232. cursor: default;
  1233. user-select: none;
  1234. overflow: hidden;
  1235. font-size: 0;
  1236. opacity: 0;
  1237. display: none;
  1238. transition: font-size 0.15s ease-out, opacity 0.05s ease-out 0.05s;
  1239. right: 100px;
  1240. bottom: 100px;
  1241. }
  1242.  
  1243. #wcBlock input[type="checkbox"],
  1244. #wcBlock input[type="radio"] {
  1245. display: none;
  1246. }
  1247.  
  1248. #wcBlock label {
  1249. padding: 0.9em 0.2em;
  1250. }
  1251.  
  1252. #wcBlock input[type="radio"]:checked+label {
  1253. background: #a22929;
  1254. }
  1255.  
  1256. #wcBlock input:hover+label {
  1257. background: #3a342f;
  1258. }
  1259.  
  1260. #wcBlockAttributes input+label::before {
  1261. content: 'Current ';
  1262. }
  1263.  
  1264. #wcBlockAttributes input:checked+label::before {
  1265. content: 'Any ';
  1266. }
  1267.  
  1268. #wcBlockHeader {
  1269. background: #3a342f;
  1270. font-weight: bold;
  1271. padding: 0.3em 0.3em;
  1272. }
  1273.  
  1274. #wcBlockPeriod,
  1275. #wcBlockAttributes,
  1276. #wcBlockButtons {
  1277. display: grid;
  1278. }
  1279.  
  1280. #wcBlockPeriod {
  1281. grid-template-columns: 23% 23% 23% 31%;
  1282. }
  1283.  
  1284. #wcBlockButtons {
  1285. grid-template-columns: 59% 40%;
  1286. column-gap: 1%;
  1287. }
  1288.  
  1289. .wcBlockButton {
  1290. background: #3a342f;
  1291. border: none;
  1292. padding: 0.6em 0.1em;
  1293. color: white;
  1294. font-size: 1em;
  1295. }
  1296.  
  1297. #wcBlockBlock {
  1298. background: #631717;
  1299. }
  1300.  
  1301. #wcBlockCancel:hover {
  1302. background: #3bad48;
  1303. }
  1304.  
  1305. #wcBlockBlock:hover {
  1306. background: #a22929;
  1307. }
  1308. \`
  1309.  
  1310. addStyle(style);
  1311.  
  1312. var html = \`
  1313. <div id="chatbox">
  1314. <div id="chatMessages"></div>
  1315. <div id="chatNotifications"></div>
  1316. <input id="chatInput" type="text" maxlength="372">
  1317. </div>
  1318. <div id="wcBlock">
  1319. <div id="wcBlockHeader">Block user for ...</div>
  1320. <div id="wcBlockPeriod">
  1321. <input class="wcBlockPeriodRadio" type="radio" name="wcBlockPeriod" value="year" id="wcBlockPeriodRadio1">
  1322. <label for="wcBlockPeriodRadio1">Year</label>
  1323. <input class="wcBlockPeriodRadio" type="radio" name="wcBlockPeriod" value="week" id="wcBlockPeriodRadio2">
  1324. <label for="wcBlockPeriodRadio2">Week</label>
  1325. <input class="wcBlockPeriodRadio" type="radio" name="wcBlockPeriod" value="day" id="wcBlockPeriodRadio3">
  1326. <label for="wcBlockPeriodRadio3">Day</label>
  1327. <input class="wcBlockPeriodRadio" type="radio" name="wcBlockPeriod" value="2h" id="wcBlockPeriodRadio4" checked>
  1328. <label for="wcBlockPeriodRadio4">Two&nbsp;hours</label>
  1329. </div>
  1330. <div id="wcBlockAttributes">
  1331. <input class="wcBlockAttribute" type="checkbox" id="wcBlockAnyColor" checked>
  1332. <label for="wcBlockAnyColor">color</label>
  1333. </div>
  1334. <div id="wcBlockButtons">
  1335. <input class="wcBlockButton" type="button" id="wcBlockBlock" value="Block">
  1336. <input class="wcBlockButton" type="button" id="wcBlockCancel" value="Cancel">
  1337. </div>
  1338. </div>
  1339. \`
  1340.  
  1341. addHTML(html, "#playUI");
  1342.  
  1343. var wcBlock = document.getElementById("wcBlock");
  1344. var wcPlayerMenuHeader = document.getElementById("wcBlockHeader");
  1345. var wcBlockPeriodRadio1 = document.getElementById("wcBlockPeriodRadio1");
  1346. var wcBlockPeriodRadio2 = document.getElementById("wcBlockPeriodRadio2");
  1347. var wcBlockPeriodRadio3 = document.getElementById("wcBlockPeriodRadio3");
  1348. var wcBlockPeriodRadio4 = document.getElementById("wcBlockPeriodRadio4");
  1349. var wcBlockAnyColor = document.getElementById("wcBlockAnyColor");
  1350. var wcBlockBlock = document.getElementById("wcBlockBlock");
  1351. var wcBlockCancel = document.getElementById("wcBlockCancel");
  1352.  
  1353. wcBlockAnyColor.addEventListener("change", function () {
  1354. if (!wcBlockAnyColor.checked) {
  1355. document.querySelector("#wcBlockAnyColor+label").style.backgroundColor = wcBlock.getAttribute("data-color");
  1356. }
  1357. else {
  1358. document.querySelector("#wcBlockAnyColor+label").style.background = "none";
  1359. }
  1360. })
  1361.  
  1362. function wcShowBlockMenu(e) {
  1363. var name = e.target.getAttribute("data-name");
  1364. var colorId = e.target.getAttribute("data-colorid");
  1365. wcBlock.setAttribute("data-name", name);
  1366. wcBlock.setAttribute("data-color", bgColorById(colorId));
  1367. wcBlock.setAttribute("data-colorid", colorId);
  1368. wcPlayerMenuHeader.textContent = \`Block \${name} for a...\`;
  1369. wcBlockPeriodRadio4.checked = true;
  1370. wcBlockAnyColor.checked = false;
  1371. document.querySelector("#wcBlockAnyColor+label").style.backgroundColor = bgColorById(colorId);
  1372. wcBlock.style.right = \`\${document.body.clientWidth - e.clientX + 20}px\`
  1373. wcBlock.style.bottom = \`\${document.body.clientHeight - e.clientY}px\`
  1374. wcBlock.style.opacity = "1";
  1375. wcBlock.style.fontSize = "1em";
  1376. wcBlock.style.display = "block";
  1377. }
  1378.  
  1379. function wcHideBlockMenu() {
  1380. wcBlock.style.opacity = "0";
  1381. wcBlock.style.fontSize = "0";
  1382. wcBlock.style.display = "none";
  1383. }
  1384.  
  1385. wcBlockCancel.addEventListener("click", wcHideBlockMenu);
  1386. wcBlockBlock.addEventListener("click", function () {
  1387. var until = Date.now() +
  1388. (wcBlockPeriodRadio4.checked ? 2 * 60 * 60 * 1000 :
  1389. (wcBlockPeriodRadio3.checked ? 24 * 60 * 60 * 1000 :
  1390. (wcBlockPeriodRadio2.checked ? 7 * 24 * 60 * 60 * 1000 :
  1391. 365 * 24 * 60 * 60 * 1000)));
  1392.  
  1393. var name = wcBlock.getAttribute("data-name");
  1394. var colorId = !(wcBlockAnyColor.checked) ? Number.parseInt(wcBlock.getAttribute("data-colorid")) : -1;
  1395. if (isNaN(colorId)) {
  1396. colorId = -1;
  1397. }
  1398. wcBlockPlayer(name, until, colorId);
  1399.  
  1400. wcNewNotification(\`\${name} has been blocked\`, 6);
  1401. wcHideBlockMenu();
  1402. });
  1403.  
  1404. var chatNotifications = document.getElementById("chatNotifications");
  1405. var chatMessages = document.getElementById("chatMessages");
  1406. var chatInput = document.getElementById("chatInput");
  1407. chatInput.addEventListener('input', resizeChatInput);
  1408.  
  1409. function resizeChatInput() {
  1410. chatInput.style.width = (chatInput.value.length + 1) + "ch";
  1411. }
  1412.  
  1413. function addStyle(styleStr) {
  1414. const style = document.createElement('style');
  1415. style.textContent = styleStr;
  1416. document.head.append(style);
  1417. }
  1418.  
  1419. function addHTML(htmlStr, selector) {
  1420. var template = document.createElement('template');
  1421. template.innerHTML = htmlStr.trim();
  1422. document.querySelector(selector).appendChild(template.content);
  1423. }
  1424.  
  1425. function bgColorById(colorId) {
  1426. if (colorId < 0 || colorId > 12) { return 0 }
  1427. 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];
  1428. return \`hsl(\${hue[colorId]}, 94%, 50%)\`;
  1429. }
  1430.  
  1431. var msgDivs = [];
  1432. var notifDivs = [];
  1433. var wsMsgSendStatus = 0;
  1434. var chatVisible = true;
  1435. var showPrivacyWarning = wcFlags.wcPrivacyWarnings;
  1436. removeExtraMessages();
  1437.  
  1438. function wcPrivacyWarning() {
  1439. var strings = [
  1440. "Walls have ears, and so do blocks",
  1441. "Do not pass any important information through this chat",
  1442. "The interlocutor may not be who he seems",
  1443. ];
  1444. var emojis = ["👀", "🤐", "🎭", "👺", "👂", "🕵️"];
  1445. wcNewNotification(strings[Math.floor(Math.random() * strings.length)] + " " + emojis[Math.floor(Math.random() * emojis.length)], 10, 1);
  1446. showPrivacyWarning = false;
  1447. }
  1448.  
  1449. function wcNewMessage(honkMsg, name, colorId) {
  1450. if (showPrivacyWarning) {
  1451. wcPrivacyWarning();
  1452. }
  1453. var color = bgColorById(colorId);
  1454. var text = wcCompatibleReplace(honkMsgToString(honkMsg));
  1455. var trimName = name.trim();
  1456. if (wcFlags.wcConsoleLog) {
  1457. console.log((trimName === "" ? "𝓷𝓸𝓷𝓪𝓶𝓮" : trimName) + ": " + text);
  1458. }
  1459.  
  1460. var msgDiv = document.createElement("div");
  1461. msgDiv.classList.add("chatMessage");
  1462.  
  1463. var msgSpanName = document.createElement("span");
  1464. msgSpanName.textContent = trimName === "" ? "⬤" : trimName;
  1465. msgSpanName.setAttribute("data-name", trimName);
  1466. msgSpanName.setAttribute("data-colorid", colorId);
  1467. msgSpanName.style.color = color;
  1468. msgSpanName.addEventListener("click", wcShowBlockMenu);
  1469. var msgSpanText = document.createElement("span");
  1470. msgSpanText.textContent = text;
  1471. msgDiv.appendChild(msgSpanName);
  1472. msgDiv.appendChild(msgSpanText);
  1473. chatMessages.appendChild(msgDiv);
  1474. msgDivs.unshift(msgDiv);
  1475. if (wcFlags.wcMsgDisplayTime !== 0) { // don't delete at all if 0. But will be deleted if limit reached
  1476. setTimeout(function () {
  1477. msgDiv.style.transition = \`opacity \${wcFlags.wcMsgDecayTime <= wcFlags.wcMsgDisplayTime ? wcFlags.wcMsgDecayTime : wcFlags.wcMsgDisplayTime}s ease-in-out\`;
  1478. msgDiv.style.opacity = "0";
  1479. }, (wcFlags.wcMsgDecayTime < wcFlags.wcMsgDisplayTime ? wcFlags.wcMsgDisplayTime - wcFlags.wcMsgDecayTime : 0.1) * 1000);
  1480. setTimeout(function () {
  1481. var index = msgDivs.indexOf(msgDiv);
  1482. if (index != -1) {
  1483. msgDiv.remove();
  1484. msgDivs.splice(index, 1);
  1485. }
  1486. }, wcFlags.wcMsgDisplayTime * 1000);
  1487. }
  1488. }
  1489.  
  1490. function showTopNotification(text, timeAlive = 4) {
  1491. var notification = doTopNotification(text);
  1492. setTimeout(function () { notification.animateOut(); notification.destroy(); }, timeAlive * 1000);
  1493. }
  1494.  
  1495. function wcNewCornerNotification(text, timeAlive = 4, type = 0) {
  1496. var notifDiv = document.createElement("div");
  1497. notifDiv.classList.add("chatNotification");
  1498. var notifSpan = document.createElement("span");
  1499. notifSpan.textContent = text;
  1500. if (type == 1) {
  1501. notifSpan.style.fontStyle = "normal";
  1502. notifSpan.style.color = "yellow";
  1503. }
  1504. notifDiv.appendChild(notifSpan);
  1505. chatNotifications.appendChild(notifDiv);
  1506. notifDivs.unshift(notifDiv);
  1507. setTimeout(function () {
  1508. notifDiv.style.transition = "opacity 1s ease-in-out, max-height .35s ease-in-out";
  1509. notifDiv.style.transitionDelay = "0s, .5s"
  1510. notifDiv.style.opacity = "0";
  1511. notifDiv.style.maxHeight = "0";
  1512. }, (timeAlive - 1) * 1000);
  1513. setTimeout(function () {
  1514. var index = notifDivs.indexOf(notifDiv);
  1515. if (index != -1) {
  1516. notifDiv.remove();
  1517. notifDivs.splice(index, 1);
  1518. }
  1519. }, timeAlive * 1000);
  1520. }
  1521.  
  1522. function wcNewNotification(text, timeAlive = 4, type = 0) {
  1523. text = wcCompatibleReplace(text);
  1524.  
  1525. if (timeAlive == undefined) {
  1526. timeAlive = 4;
  1527. }
  1528. if (wcFlags.wcDefaultNotifications) {
  1529. showTopNotification(text, timeAlive);
  1530. }
  1531. else {
  1532. wcNewCornerNotification(text, timeAlive, type);
  1533. }
  1534. }
  1535.  
  1536. function removeExtraMessages() {
  1537. if (msgDivs.length > wcFlags.wcMessageLimit) {
  1538. for (var i = msgDivs.length - 1; i > wcFlags.wcMessageLimit; i--) {
  1539. msgDivs[i].remove();
  1540. msgDivs.splice(i);
  1541. }
  1542. }
  1543. setTimeout(removeExtraMessages, 2000);
  1544. }
  1545.  
  1546. function hideChatInput() {
  1547. chatInput.style.visibility = 'hidden';
  1548. chatInput.blur();
  1549. }
  1550.  
  1551. function toggleChatInput() {
  1552. if (chatInput.style.visibility !== 'visible') {
  1553. chatInput.style.visibility = 'visible';
  1554. showChat();
  1555. chatInput.focus();
  1556. }
  1557. else {
  1558. hideChatInput();
  1559. }
  1560. }
  1561.  
  1562. function showChat() {
  1563. chatVisible = true;
  1564. chatMessages.style.opacity = '1';
  1565. chatMessages.style.pointerEvents = 'auto';
  1566. }
  1567.  
  1568. function toggleChat() {
  1569. chatVisible = !chatVisible;
  1570. if (chatVisible) {
  1571. chatMessages.style.opacity = '1';
  1572. chatMessages.style.pointerEvents = 'auto';
  1573. wcNewNotification("Chat is visible", 2);
  1574. }
  1575. else {
  1576. chatMessages.style.opacity = '0';
  1577. chatMessages.style.pointerEvents = 'none';
  1578. hideChatInput();
  1579. wcNewNotification("Chat is hidden", 2);
  1580. }
  1581. }
  1582.  
  1583. function wcIsPlayerBlocked(name, colorId) {
  1584. if (!(name in wcFlags.wcBlockedPlayers)) {
  1585. return false;
  1586. }
  1587. else {
  1588. for (const one of wcFlags.wcBlockedPlayers[name]) {
  1589. if (one.until > Date.now() && (!('colorId' in one) || one.colorId == colorId)) {
  1590. return true;
  1591. }
  1592. }
  1593. }
  1594. return false;
  1595. }
  1596.  
  1597. function wcBlockPlayer(name, until, colorId = -1) {
  1598. wcLoadBlockedPlayers(false);
  1599.  
  1600. if (!(name in wcFlags.wcBlockedPlayers)) {
  1601. wcFlags.wcBlockedPlayers[name] = [];
  1602. }
  1603.  
  1604. if (colorId === -1) {
  1605. wcFlags.wcBlockedPlayers[name].push({ 'until': until });
  1606. }
  1607. else {
  1608. wcFlags.wcBlockedPlayers[name].push({ 'until': until, 'colorId': colorId });
  1609. }
  1610. wcSaveBlockedPlayers();
  1611. }
  1612.  
  1613. function wcSaveBlockedPlayers() {
  1614. localStorage.setItem("wcBlockedPlayers", JSON.stringify(wcFlags.wcBlockedPlayers));
  1615. }
  1616.  
  1617. function wcLoadBlockedPlayers(saveIfChanged = true) {
  1618. var lsBlockedPlayers = localStorage.getItem("wcBlockedPlayers");
  1619. var wasChanged = false;
  1620.  
  1621. try {
  1622. var parsedBlockedPlayers = JSON.parse(lsBlockedPlayers);
  1623. if (parsedBlockedPlayers === null) {
  1624. parsedBlockedPlayers = {}
  1625. }
  1626. }
  1627. catch {
  1628. var parsedBlockedPlayers = {};
  1629. wasChanged = true;
  1630. }
  1631.  
  1632. for (var name in parsedBlockedPlayers) {
  1633. const properties = parsedBlockedPlayers[name];
  1634. if (Array.isArray(properties)) {
  1635. var i = properties.length;
  1636. while (i--) {
  1637. const one = properties[i];
  1638. if (typeof one !== 'object'
  1639. || one === null
  1640. || !('until' in one)
  1641. || one.until < Date.now()
  1642. || ('colorId' in one && (!Number.isInteger(one.colorId) || one.colorId < 0 || one.colorId > 12))) {
  1643. properties.splice(i, 1);
  1644. wasChanged = true;
  1645. }
  1646. }
  1647. if (properties.length === 0) {
  1648. delete parsedBlockedPlayers[name];
  1649. wasChanged = true;
  1650. }
  1651. }
  1652. else {
  1653. delete parsedBlockedPlayers.name;
  1654. wasChanged = true;
  1655. }
  1656. }
  1657.  
  1658. wcFlags.wcBlockedPlayers = parsedBlockedPlayers;
  1659.  
  1660. if (saveIfChanged && wasChanged) {
  1661. wcSaveBlockedPlayers();
  1662. }
  1663. }
  1664.  
  1665. var wcReplacements = {}, wcRECompat, wcCompatibleReplace;
  1666.  
  1667. (function () {
  1668. var compatibleReplacements = {
  1669. "💔": ["</3"],
  1670. "😕": [":-/"],
  1671. "😢": [":'("],
  1672. "🙁": ["😟", ":("],
  1673. "❤️": ["<3"],
  1674. "😇": ["0:-)"],
  1675. "😂": [":'-)"],
  1676. "😗": [":*"],
  1677. "😐": [":|"],
  1678. "😮": [":-O"],
  1679. "😡": [":@"],
  1680. "🙂": ["😊", ":-)"],
  1681. "😄": [":D"],
  1682. "😭": [";("],
  1683. "😛": [":P"],
  1684. "😅": [",:-)"],
  1685. "😒": [":s"],
  1686. "😉": [";)"],
  1687. "🙃": ["🙂", "😊", "(-:"],
  1688. "🤐": ["🙊", ":secret:"],
  1689. "🕵️": ["👁", ":detective:"],
  1690. }
  1691.  
  1692. var testContext = document.createElement("canvas").getContext('2d');
  1693. function isEmojiAvailable(em) {
  1694. return testContext.measureText(em).width > 8;
  1695. }
  1696.  
  1697. for (var em in compatibleReplacements) {
  1698. if (!isEmojiAvailable(em)) {
  1699. for (var i = 0; i < compatibleReplacements[em].length; i++) {
  1700. if (i == compatibleReplacements[em].length - 1 || isEmojiAvailable(compatibleReplacements[em][i])) {
  1701. wcReplacements[em] = compatibleReplacements[em][i];
  1702. break;
  1703. }
  1704. }
  1705. }
  1706. }
  1707.  
  1708. testContext.canvas.remove();
  1709.  
  1710. if (Object.keys(wcReplacements).length > 0) {
  1711. wcRECompat = new RegExp(Object.keys(wcReplacements).join("|"), "gi");
  1712. wcCompatibleReplace = function (str) {
  1713. return str.replace(wcRECompat, function (matched) {
  1714. return wcReplacements[matched];
  1715. });
  1716. }
  1717. }
  1718. else {
  1719. wcReplacements = null;
  1720. wcCompatibleReplace = function (str) {
  1721. return str;
  1722. };
  1723. }
  1724. }());
  1725.  
  1726. var wcEmoticons = {
  1727. "</3": "💔",
  1728. "<\\\\3": "💔",
  1729. ":-/": "😕",
  1730. ":'-(": "😢",
  1731. ":'(": "😢",
  1732. ":(": "🙁",
  1733. ":-(": "🙁",
  1734. "<3": "❤️",
  1735. "O:-)": "😇",
  1736. "0:-)": "😇",
  1737. "O:)": "😇",
  1738. "0:)": "😇",
  1739. ":'-)": "😂",
  1740. ":')": "😂",
  1741. ":-*": "😗",
  1742. ":*": "😗",
  1743. ":-|": "😐",
  1744. ":|": "😐",
  1745. ":-O": "😮",
  1746. ":O": "😮",
  1747. ":@": "😡",
  1748. ":)": "🙂",
  1749. ":-)": "🙂",
  1750. "=)": "🙂",
  1751. "^^": "😄",
  1752. ":D": "😃",
  1753. ":-D": "😃",
  1754. "=D": "😃",
  1755. "XD": "😆",
  1756. ";(": "😭",
  1757. ":-P": "😛",
  1758. ":P": "😛",
  1759. ",:-)": "😅",
  1760. ":\$": "😒",
  1761. ":S": "😒",
  1762. ";-)": "😉",
  1763. ";)": "😉",
  1764. "(:": "🙃",
  1765. "(-:": "🙃",
  1766. "(=": "🙃"
  1767. }
  1768.  
  1769. var wcEmRe = /(^|\\s)(['\\-\\\$\\(\\)*,/:;@\\\\\\^\\|<=03DOPSX]{2,4})(\$|\\s)/gi;
  1770.  
  1771. function wcEmoticonsToEmoji(src) {
  1772. wcEmRe.lastIndex = 0;
  1773. var result = "",
  1774. prevIndex = 0,
  1775. REsult;
  1776. while (REsult = wcEmRe.exec(src)) {
  1777. if (REsult[2].toUpperCase() in wcEmoticons) {
  1778. if (REsult[1].length == 1) {
  1779. result += src.substring(prevIndex, REsult.index + 1) + wcEmoticons[REsult[2].toUpperCase()];
  1780. }
  1781. else {
  1782. result += wcEmoticons[REsult[2].toUpperCase()];
  1783. }
  1784.  
  1785. if (REsult[3].length != 0) {
  1786. wcEmRe.lastIndex -= 1;
  1787. }
  1788.  
  1789. prevIndex = wcEmRe.lastIndex;
  1790. }
  1791. else if (REsult[3].length != 0) {
  1792. wcEmRe.lastIndex -= 1;
  1793. }
  1794. }
  1795. result += src.substring(prevIndex);
  1796. return result;
  1797. }
  1798.  
  1799. document.body.addEventListener('keydown', function (e) {
  1800. if (e.keyCode == 13) {
  1801. if (playingAndReady) {
  1802. toggleChatInput();
  1803. }
  1804. }
  1805. else if (e.keyCode == 27) {
  1806. hideChatInput()
  1807. }
  1808. else if (e.keyCode == 67) {
  1809. toggleChat();
  1810. }
  1811. })
  1812.  
  1813. chatInput.addEventListener('focusout', function () {
  1814. chatInput.style.visibility = 'hidden';
  1815. });
  1816.  
  1817. chatInput.addEventListener('keydown', function (e) {
  1818. e.stopPropagation();
  1819. if (e.keyCode == 27) {
  1820. hideChatInput();
  1821. }
  1822. else if (e.keyCode == 13) {
  1823. if (chatInput.value.length == 0) {
  1824. hideChatInput();
  1825. }
  1826. else {
  1827. if (wsMsgSendStatus === 0) {
  1828. var message = wcFlags.wcConvertEmoticons ? strToHonkMsg(wcEmoticonsToEmoji(chatInput.value)) : strToHonkMsg(chatInput.value);
  1829. if (typeof (message) == "number") {
  1830. if (message == 0) {
  1831. wcNewNotification("Message length is 0");
  1832. }
  1833. else {
  1834. wcNewNotification(\`Shorten the message by about \${message - 186} characters\`, 5);
  1835. }
  1836. }
  1837. else {
  1838. wcSendMessage(message);
  1839. chatInput.value = "";
  1840. hideChatInput();
  1841. resizeChatInput();
  1842. }
  1843. }
  1844. else {
  1845. wcNewNotification("Please wait...", 2);
  1846. }
  1847. }
  1848. }
  1849. })
  1850.  
  1851. chatInput.addEventListener('keyup', function (e) {
  1852. e.stopPropagation();
  1853. })`
  1854.  
  1855. function waitPageReady(callback) {
  1856. if (typeof(getPlayer) != "function" && typeof(ddEl) != "object") {
  1857. requestAnimationFrame(function(){waitPageReady(callback)});
  1858. }
  1859. else {
  1860. setTimeout(callback,0);
  1861. }
  1862. }
  1863.  
  1864. function addScript() {
  1865. var template = document.createElement('script');
  1866. template.innerHTML = source;
  1867. document.body.appendChild(template);
  1868. }
  1869.  
  1870. waitPageReady(addScript);
  1871.  
  1872. })();