Wrong Chat

Just chat to chat with nearby players

当前为 2020-11-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Wrong Chat
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3.3
  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. if (players.length > 0) {
  987. var code = wcMessage.charCodeAt(wcMessagePos) + 70;
  988. wcMessagePos += 1;
  989. wsSendMsg(sendAction.HONK, code);
  990. players[0].doHonk(code);
  991. if (wcMessagePos < wcMessage.length) {
  992. setTimeout(wcSendMsgHonk, ((wcMessagePos < 13e0) ? 50e0 : ((wcMessagePos < 26e0) ? 65e0 : 85e0)));
  993. }
  994. else {
  995. wsMsgSendStatus = 0;
  996. }
  997. }
  998. else {
  999. wsMsgSendStatus = 0;
  1000. }
  1001. }
  1002.  
  1003. function wcSendMessage(message) {
  1004. wcMessage = String.fromCharCode(1) + String.fromCharCode(57) + message;
  1005. wcMessagePos = 0;
  1006. wsMsgSendStatus = 1;
  1007. wcSendMsgHonk();
  1008. }
  1009.  
  1010. function wcMsgHonkHandler(player, value) {
  1011. if (player.msgStatus == 0) {
  1012. if (value == 71 && !wcIsPlayerBlocked(player.name, player.skinBlock)) {
  1013. player.msgStatus = 1;
  1014. }
  1015. else return;
  1016. }
  1017. else if (player.msgStatus == 1) {
  1018. if (value == 127) {
  1019. player.msgStatus = 2;
  1020. }
  1021. else {
  1022. player.msgStatus = 0;
  1023. }
  1024. }
  1025. else if (player.msgStatus == 2) {
  1026. if (value >= 71 && value <= 73) {
  1027. player.msgStatus = 3;
  1028. player.message = String.fromCharCode(value - 70);
  1029. }
  1030. else {
  1031. player.msgStatus = 0;
  1032. }
  1033. }
  1034. else if (player.msgStatus == 3) {
  1035. player.msgStatus = 4;
  1036. player.msgLength = value - 69 + 2;
  1037. player.message += String.fromCharCode(value - 69);
  1038. }
  1039. else {
  1040. player.message += String.fromCharCode(value - 70);
  1041. if (player.message.length >= player.msgLength) {
  1042. wcNewMessage(player.message, player.name, player.skinBlock);
  1043. player.msgStatus = 0;
  1044. }
  1045. }
  1046. }
  1047.  
  1048. function honkEndWC() {
  1049. if (wsMsgSendStatus === 0) {
  1050. var e = Date.now();
  1051. if (lastHonkTime < e) {
  1052. var t = clamp(t = e - honkStartTime, 0, 1e3);
  1053. lastHonkTime = e + t,
  1054. t = iLerp(0, 1e3, t),
  1055. t *= 255,
  1056. t = Math.floor(t),
  1057. wsSendMsg(sendAction.HONK, t);
  1058. for (var n = 0; n < players.length; n++) {
  1059. var a = players[n];
  1060. a.isMyPlayer && a.doHonk(Math.max(70, t))
  1061. }
  1062. }
  1063. }
  1064. }
  1065.  
  1066. function getPlayerWC(e, t) {
  1067. var n;
  1068. void 0 === t && (t = players);
  1069. for (var a = 0; a < t.length; a++)
  1070. if ((n = t[a]).id == e)
  1071. return n;
  1072. return n = {
  1073. id: e,
  1074. pos: [0, 0],
  1075. drawPos: [-1, -1],
  1076. drawPosSet: !1,
  1077. serverPos: [0, 0],
  1078. dir: 0,
  1079. isMyPlayer: 0 === e,
  1080. isDead: !1,
  1081. deathWasCertain: !1,
  1082. didUncertainDeathLastTick: !1,
  1083. isDeadTimer: 0,
  1084. uncertainDeathPosition: [0, 0],
  1085. message: "",
  1086. msgStatus: 0,
  1087. msgLength: 0,
  1088. die: function (e) {
  1089. if (e = !!e, this.isDead)
  1090. this.deathWasCertain = e || this.deathWasCertain;
  1091. else if (e || !this.didUncertainDeathLastTick) {
  1092. e || (this.didUncertainDeathLastTick = !0, this.uncertainDeathPosition = [this.pos[0], this.pos[1]]),
  1093. this.isDead = !0,
  1094. this.deathWasCertain = e,
  1095. this.deadAnimParts = [0],
  1096. this.isDeadTimer = 0,
  1097. this.isMyPlayer && doCamShakeDir(this.dir);
  1098. for (var t = 0; ;) {
  1099. if ((t += .4 * Math.random() + .5) >= 2 * Math.PI) {
  1100. this.deadAnimParts.push(2 * Math.PI);
  1101. break
  1102. }
  1103. this.deadAnimParts.push(t),
  1104. this.deadAnimPartsRandDist.push(Math.random())
  1105. }
  1106. }
  1107. },
  1108. undoDie: function () {
  1109. this.isDead = !1
  1110. },
  1111. deadAnimParts: [],
  1112. deadAnimPartsRandDist: [],
  1113. addHitLine: function (e, t) {
  1114. this.hitLines.push({
  1115. pos: e,
  1116. vanishTimer: 0,
  1117. color: t
  1118. })
  1119. },
  1120. hitLines: [],
  1121. doHonk: function (e) {
  1122. this.honkTimer = 0,
  1123. this.honkMaxTime = e,
  1124. "joris" == this.name.toLowerCase() && (null == honkSfx && (honkSfx = new Audio("/honk.mp3")), honkSfx.play());
  1125. wcMsgHonkHandler(this, e);
  1126. },
  1127. moveRelativeToServerPosNextFrame: !1,
  1128. lastServerPosSentTime: 0,
  1129. honkTimer: 0,
  1130. honkMaxTime: 0,
  1131. trails: [],
  1132. name: "",
  1133. skinBlock: 0,
  1134. lastBlock: null,
  1135. hasReceivedPosition: !1
  1136. },
  1137. t.push(n),
  1138. n.isMyPlayer && (myPlayer = n),
  1139. n
  1140. }
  1141.  
  1142. getPlayer = getPlayerWC;
  1143. honkEnd = honkEndWC;
  1144.  
  1145. var style = \`
  1146. #chatbox {
  1147. position: absolute;
  1148. right: 0;
  1149. bottom: 0;
  1150. }
  1151.  
  1152. #chatbox > * {
  1153. clear:both;
  1154. float:right;
  1155. }
  1156.  
  1157. #chatMessages > * {
  1158. clear:both;
  1159. float:right;
  1160. }
  1161.  
  1162. #chatNotifications > * {
  1163. clear:both;
  1164. float:right;
  1165. }
  1166.  
  1167. .chatMessage, .chatNotification {
  1168. display: flex;
  1169. background: #2d2824;
  1170. border: solid 2px #332d29;
  1171. margin: 1px 7px;
  1172. border-radius: 9px;
  1173. overflow: hidden;
  1174. max-width: 450px;
  1175. user-select: text;
  1176. opacity: 1;
  1177. }
  1178.  
  1179. .chatNotification {
  1180. max-height: 100px;
  1181. }
  1182.  
  1183. .chatNotification > span {
  1184. color: #fff;
  1185. font-style: italic;
  1186. display: flex;
  1187. align-items: center;
  1188. padding: 4px 10px;
  1189. }
  1190.  
  1191. #chatInput {
  1192. display: inline-block;
  1193. background: #7a6d62;
  1194. color: #000000;
  1195. border: solid 4px #3a342f;
  1196. margin: 1px 0 0 0;
  1197. padding: 0 0.2em;
  1198. font-size: 1.1em;
  1199. line-height: 1.4em;
  1200. outline: none;
  1201. min-width: 250px;
  1202. font-family: "Lucida Console", Monaco, monospace;
  1203. visibility: hidden;
  1204. }
  1205.  
  1206. .chatMessage > span {
  1207. display: flex;
  1208. align-items: center;
  1209. padding-top: 4px;
  1210. padding-bottom: 4px;
  1211. }
  1212.  
  1213. .chatMessage span:last-of-type{
  1214. color: #fff;
  1215. background: #413a35;
  1216. padding-left: 10px;
  1217. padding-right: 10px;
  1218. overflow-wrap: anywhere;
  1219. }
  1220.  
  1221. .chatMessage span:first-of-type{
  1222. color: #ffffff80;
  1223. font-weight: bold;
  1224. padding-left: 5px;
  1225. padding-right: 5px;
  1226. cursor: pointer;
  1227. }
  1228.  
  1229. #wcBlock {
  1230. position: absolute;
  1231. min-width: 300px;
  1232. background: #4d453e;
  1233. border: solid 1px #000000;
  1234. color: #ffffff;
  1235. text-align: center;
  1236. box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.1);
  1237. cursor: default;
  1238. user-select: none;
  1239. overflow: hidden;
  1240. font-size: 0;
  1241. opacity: 0;
  1242. display: none;
  1243. transition: font-size 0.15s ease-out, opacity 0.05s ease-out 0.05s;
  1244. right: 100px;
  1245. bottom: 100px;
  1246. }
  1247.  
  1248. #wcBlock input[type="checkbox"],
  1249. #wcBlock input[type="radio"] {
  1250. display: none;
  1251. }
  1252.  
  1253. #wcBlock label {
  1254. padding: 0.9em 0.2em;
  1255. }
  1256.  
  1257. #wcBlock input[type="radio"]:checked+label {
  1258. background: #a22929;
  1259. }
  1260.  
  1261. #wcBlock input:hover+label {
  1262. background: #3a342f;
  1263. }
  1264.  
  1265. #wcBlockAttributes input+label::before {
  1266. content: 'Current ';
  1267. }
  1268.  
  1269. #wcBlockAttributes input:checked+label::before {
  1270. content: 'Any ';
  1271. }
  1272.  
  1273. #wcBlockHeader {
  1274. background: #3a342f;
  1275. font-weight: bold;
  1276. padding: 0.3em 0.3em;
  1277. }
  1278.  
  1279. #wcBlockPeriod,
  1280. #wcBlockAttributes,
  1281. #wcBlockButtons {
  1282. display: grid;
  1283. }
  1284.  
  1285. #wcBlockPeriod {
  1286. grid-template-columns: 23% 23% 23% 31%;
  1287. }
  1288.  
  1289. #wcBlockButtons {
  1290. grid-template-columns: 59% 40%;
  1291. column-gap: 1%;
  1292. }
  1293.  
  1294. .wcBlockButton {
  1295. background: #3a342f;
  1296. border: none;
  1297. padding: 0.6em 0.1em;
  1298. color: white;
  1299. font-size: 1em;
  1300. }
  1301.  
  1302. #wcBlockBlock {
  1303. background: #631717;
  1304. }
  1305.  
  1306. #wcBlockCancel:hover {
  1307. background: #3bad48;
  1308. }
  1309.  
  1310. #wcBlockBlock:hover {
  1311. background: #a22929;
  1312. }
  1313. \`
  1314.  
  1315. addStyle(style);
  1316.  
  1317. var html = \`
  1318. <div id="chatbox">
  1319. <div id="chatMessages"></div>
  1320. <div id="chatNotifications"></div>
  1321. <input id="chatInput" type="text" maxlength="372">
  1322. </div>
  1323. <div id="wcBlock">
  1324. <div id="wcBlockHeader">Block user for ...</div>
  1325. <div id="wcBlockPeriod">
  1326. <input class="wcBlockPeriodRadio" type="radio" name="wcBlockPeriod" value="year" id="wcBlockPeriodRadio1">
  1327. <label for="wcBlockPeriodRadio1">Year</label>
  1328. <input class="wcBlockPeriodRadio" type="radio" name="wcBlockPeriod" value="week" id="wcBlockPeriodRadio2">
  1329. <label for="wcBlockPeriodRadio2">Week</label>
  1330. <input class="wcBlockPeriodRadio" type="radio" name="wcBlockPeriod" value="day" id="wcBlockPeriodRadio3">
  1331. <label for="wcBlockPeriodRadio3">Day</label>
  1332. <input class="wcBlockPeriodRadio" type="radio" name="wcBlockPeriod" value="2h" id="wcBlockPeriodRadio4" checked>
  1333. <label for="wcBlockPeriodRadio4">Two&nbsp;hours</label>
  1334. </div>
  1335. <div id="wcBlockAttributes">
  1336. <input class="wcBlockAttribute" type="checkbox" id="wcBlockAnyColor" checked>
  1337. <label for="wcBlockAnyColor">color</label>
  1338. </div>
  1339. <div id="wcBlockButtons">
  1340. <input class="wcBlockButton" type="button" id="wcBlockBlock" value="Block">
  1341. <input class="wcBlockButton" type="button" id="wcBlockCancel" value="Cancel">
  1342. </div>
  1343. </div>
  1344. \`
  1345.  
  1346. addHTML(html, "#playUI");
  1347.  
  1348. var wcBlock = document.getElementById("wcBlock");
  1349. var wcPlayerMenuHeader = document.getElementById("wcBlockHeader");
  1350. var wcBlockPeriodRadio1 = document.getElementById("wcBlockPeriodRadio1");
  1351. var wcBlockPeriodRadio2 = document.getElementById("wcBlockPeriodRadio2");
  1352. var wcBlockPeriodRadio3 = document.getElementById("wcBlockPeriodRadio3");
  1353. var wcBlockPeriodRadio4 = document.getElementById("wcBlockPeriodRadio4");
  1354. var wcBlockAnyColor = document.getElementById("wcBlockAnyColor");
  1355. var wcBlockBlock = document.getElementById("wcBlockBlock");
  1356. var wcBlockCancel = document.getElementById("wcBlockCancel");
  1357.  
  1358. wcBlockAnyColor.addEventListener("change", function () {
  1359. if (!wcBlockAnyColor.checked) {
  1360. document.querySelector("#wcBlockAnyColor+label").style.backgroundColor = wcBlock.getAttribute("data-color");
  1361. }
  1362. else {
  1363. document.querySelector("#wcBlockAnyColor+label").style.background = "none";
  1364. }
  1365. })
  1366.  
  1367. function wcShowBlockMenu(e) {
  1368. var name = e.target.getAttribute("data-name");
  1369. var colorId = e.target.getAttribute("data-colorid");
  1370. wcBlock.setAttribute("data-name", name);
  1371. wcBlock.setAttribute("data-color", bgColorById(colorId));
  1372. wcBlock.setAttribute("data-colorid", colorId);
  1373. wcPlayerMenuHeader.textContent = \`Block \${name} for a...\`;
  1374. wcBlockPeriodRadio4.checked = true;
  1375. wcBlockAnyColor.checked = false;
  1376. document.querySelector("#wcBlockAnyColor+label").style.backgroundColor = bgColorById(colorId);
  1377. wcBlock.style.right = \`\${document.body.clientWidth - e.clientX + 20}px\`
  1378. wcBlock.style.bottom = \`\${document.body.clientHeight - e.clientY}px\`
  1379. wcBlock.style.opacity = "1";
  1380. wcBlock.style.fontSize = "1em";
  1381. wcBlock.style.display = "block";
  1382. }
  1383.  
  1384. function wcHideBlockMenu() {
  1385. wcBlock.style.opacity = "0";
  1386. wcBlock.style.fontSize = "0";
  1387. wcBlock.style.display = "none";
  1388. }
  1389.  
  1390. wcBlockCancel.addEventListener("click", wcHideBlockMenu);
  1391. wcBlockBlock.addEventListener("click", function () {
  1392. var until = Date.now() +
  1393. (wcBlockPeriodRadio4.checked ? 2 * 60 * 60 * 1000 :
  1394. (wcBlockPeriodRadio3.checked ? 24 * 60 * 60 * 1000 :
  1395. (wcBlockPeriodRadio2.checked ? 7 * 24 * 60 * 60 * 1000 :
  1396. 365 * 24 * 60 * 60 * 1000)));
  1397.  
  1398. var name = wcBlock.getAttribute("data-name");
  1399. var colorId = !(wcBlockAnyColor.checked) ? Number.parseInt(wcBlock.getAttribute("data-colorid")) : -1;
  1400. if (isNaN(colorId)) {
  1401. colorId = -1;
  1402. }
  1403. wcBlockPlayer(name, until, colorId);
  1404.  
  1405. wcNewNotification(\`\${name} has been blocked\`, 6);
  1406. wcHideBlockMenu();
  1407. });
  1408.  
  1409. var chatNotifications = document.getElementById("chatNotifications");
  1410. var chatMessages = document.getElementById("chatMessages");
  1411. var chatInput = document.getElementById("chatInput");
  1412. chatInput.addEventListener('input', resizeChatInput);
  1413.  
  1414. function resizeChatInput() {
  1415. chatInput.style.width = (chatInput.value.length + 1) + "ch";
  1416. }
  1417.  
  1418. function addStyle(styleStr) {
  1419. const style = document.createElement('style');
  1420. style.textContent = styleStr;
  1421. document.head.append(style);
  1422. }
  1423.  
  1424. function addHTML(htmlStr, selector) {
  1425. var template = document.createElement('template');
  1426. template.innerHTML = htmlStr.trim();
  1427. document.querySelector(selector).appendChild(template.content);
  1428. }
  1429.  
  1430. function bgColorById(colorId) {
  1431. if (colorId < 0 || colorId > 12) { return 0 }
  1432. 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];
  1433. return \`hsl(\${hue[colorId]}, 94%, 50%)\`;
  1434. }
  1435.  
  1436. function colorNameById(colorId) {
  1437. if (colorId < 0 || colorId > 12) { return "" }
  1438. var colors = ["red", "pink", "dark pink", "light purple", "dark purple", "dark blue", "light blue", "light green", "dark green", "olive", "yellow", "orange", "gold"];
  1439. return(colors[colorId]);
  1440. }
  1441.  
  1442. var msgDivs = [];
  1443. var notifDivs = [];
  1444. var wsMsgSendStatus = 0;
  1445. var chatVisible = true;
  1446. var showPrivacyWarning = wcFlags.wcPrivacyWarnings;
  1447. removeExtraMessages();
  1448.  
  1449. function wcPrivacyWarning() {
  1450. var strings = [
  1451. "Walls have ears, and so do blocks",
  1452. "Do not pass any important information through this chat",
  1453. "The interlocutor may not be who he seems",
  1454. ];
  1455. var emojis = ["👀", "🤐", "🎭", "👺", "👂", "🕵️"];
  1456. wcNewNotification(strings[Math.floor(Math.random() * strings.length)] + " " + emojis[Math.floor(Math.random() * emojis.length)], 10, 1);
  1457. showPrivacyWarning = false;
  1458. }
  1459.  
  1460. function wcNewMessage(honkMsg, name, colorId) {
  1461. if (showPrivacyWarning) {
  1462. wcPrivacyWarning();
  1463. }
  1464. var color = bgColorById(colorId);
  1465. var text = wcCompatibleReplace(honkMsgToString(honkMsg));
  1466. var trimName = name.trim();
  1467. if (wcFlags.wcConsoleLog) {
  1468. console.log((trimName === "" ? \`(\${colorNameById(colorId)})\` : trimName) + ": " + text);
  1469. }
  1470.  
  1471. var msgDiv = document.createElement("div");
  1472. msgDiv.classList.add("chatMessage");
  1473.  
  1474. var msgSpanName = document.createElement("span");
  1475. msgSpanName.textContent = trimName === "" ? "⬤" : trimName;
  1476. msgSpanName.setAttribute("data-name", trimName);
  1477. msgSpanName.setAttribute("data-colorid", colorId);
  1478. msgSpanName.style.color = color;
  1479. msgSpanName.addEventListener("click", wcShowBlockMenu);
  1480. var msgSpanText = document.createElement("span");
  1481. msgSpanText.textContent = text;
  1482. msgDiv.appendChild(msgSpanName);
  1483. msgDiv.appendChild(msgSpanText);
  1484. chatMessages.appendChild(msgDiv);
  1485. msgDivs.unshift(msgDiv);
  1486. if (wcFlags.wcMsgDisplayTime !== 0) { // don't delete at all if 0. But will be deleted if limit reached
  1487. setTimeout(function () {
  1488. msgDiv.style.transition = \`opacity \${wcFlags.wcMsgDecayTime <= wcFlags.wcMsgDisplayTime ? wcFlags.wcMsgDecayTime : wcFlags.wcMsgDisplayTime}s ease-in-out\`;
  1489. msgDiv.style.opacity = "0";
  1490. }, (wcFlags.wcMsgDecayTime < wcFlags.wcMsgDisplayTime ? wcFlags.wcMsgDisplayTime - wcFlags.wcMsgDecayTime : 0.1) * 1000);
  1491. setTimeout(function () {
  1492. var index = msgDivs.indexOf(msgDiv);
  1493. if (index != -1) {
  1494. msgDiv.remove();
  1495. msgDivs.splice(index, 1);
  1496. }
  1497. }, wcFlags.wcMsgDisplayTime * 1000);
  1498. }
  1499. }
  1500.  
  1501. function showTopNotification(text, timeAlive = 4) {
  1502. var notification = doTopNotification(text);
  1503. setTimeout(function () { notification.animateOut(); notification.destroy(); }, timeAlive * 1000);
  1504. }
  1505.  
  1506. function wcNewCornerNotification(text, timeAlive = 4, type = 0) {
  1507. var notifDiv = document.createElement("div");
  1508. notifDiv.classList.add("chatNotification");
  1509. var notifSpan = document.createElement("span");
  1510. notifSpan.textContent = text;
  1511. if (type == 1) {
  1512. notifSpan.style.fontStyle = "normal";
  1513. notifSpan.style.color = "yellow";
  1514. }
  1515. notifDiv.appendChild(notifSpan);
  1516. chatNotifications.appendChild(notifDiv);
  1517. notifDivs.unshift(notifDiv);
  1518. setTimeout(function () {
  1519. notifDiv.style.transition = "opacity 1s ease-in-out, max-height .35s ease-in-out";
  1520. notifDiv.style.transitionDelay = "0s, .5s"
  1521. notifDiv.style.opacity = "0";
  1522. notifDiv.style.maxHeight = "0";
  1523. }, (timeAlive - 1) * 1000);
  1524. setTimeout(function () {
  1525. var index = notifDivs.indexOf(notifDiv);
  1526. if (index != -1) {
  1527. notifDiv.remove();
  1528. notifDivs.splice(index, 1);
  1529. }
  1530. }, timeAlive * 1000);
  1531. }
  1532.  
  1533. function wcNewNotification(text, timeAlive = 4, type = 0) {
  1534. text = wcCompatibleReplace(text);
  1535.  
  1536. if (timeAlive == undefined) {
  1537. timeAlive = 4;
  1538. }
  1539. if (wcFlags.wcDefaultNotifications) {
  1540. showTopNotification(text, timeAlive);
  1541. }
  1542. else {
  1543. wcNewCornerNotification(text, timeAlive, type);
  1544. }
  1545. }
  1546.  
  1547. function removeExtraMessages() {
  1548. if (msgDivs.length > wcFlags.wcMessageLimit) {
  1549. for (var i = msgDivs.length - 1; i > wcFlags.wcMessageLimit; i--) {
  1550. msgDivs[i].remove();
  1551. msgDivs.splice(i);
  1552. }
  1553. }
  1554. setTimeout(removeExtraMessages, 2000);
  1555. }
  1556.  
  1557. function hideChatInput() {
  1558. chatInput.style.visibility = 'hidden';
  1559. chatInput.blur();
  1560. }
  1561.  
  1562. function toggleChatInput() {
  1563. if (chatInput.style.visibility !== 'visible') {
  1564. chatInput.style.visibility = 'visible';
  1565. showChat();
  1566. chatInput.focus();
  1567. }
  1568. else {
  1569. hideChatInput();
  1570. }
  1571. }
  1572.  
  1573. function showChat() {
  1574. chatVisible = true;
  1575. chatMessages.style.opacity = '1';
  1576. chatMessages.style.pointerEvents = 'auto';
  1577. }
  1578.  
  1579. function toggleChat() {
  1580. chatVisible = !chatVisible;
  1581. if (chatVisible) {
  1582. chatMessages.style.opacity = '1';
  1583. chatMessages.style.pointerEvents = 'auto';
  1584. wcNewNotification("Chat is visible", 2);
  1585. }
  1586. else {
  1587. chatMessages.style.opacity = '0';
  1588. chatMessages.style.pointerEvents = 'none';
  1589. hideChatInput();
  1590. wcNewNotification("Chat is hidden", 2);
  1591. }
  1592. }
  1593.  
  1594. function wcIsPlayerBlocked(name, colorId) {
  1595. if (!(name in wcFlags.wcBlockedPlayers)) {
  1596. return false;
  1597. }
  1598. else {
  1599. for (const one of wcFlags.wcBlockedPlayers[name]) {
  1600. if (one.until > Date.now() && (!('colorId' in one) || one.colorId == colorId)) {
  1601. return true;
  1602. }
  1603. }
  1604. }
  1605. return false;
  1606. }
  1607.  
  1608. function wcBlockPlayer(name, until, colorId = -1) {
  1609. wcLoadBlockedPlayers(false);
  1610.  
  1611. if (!(name in wcFlags.wcBlockedPlayers)) {
  1612. wcFlags.wcBlockedPlayers[name] = [];
  1613. }
  1614.  
  1615. if (colorId === -1) {
  1616. wcFlags.wcBlockedPlayers[name].push({ 'until': until });
  1617. }
  1618. else {
  1619. wcFlags.wcBlockedPlayers[name].push({ 'until': until, 'colorId': colorId });
  1620. }
  1621. wcSaveBlockedPlayers();
  1622. }
  1623.  
  1624. function wcSaveBlockedPlayers() {
  1625. localStorage.setItem("wcBlockedPlayers", JSON.stringify(wcFlags.wcBlockedPlayers));
  1626. }
  1627.  
  1628. function wcLoadBlockedPlayers(saveIfChanged = true) {
  1629. var lsBlockedPlayers = localStorage.getItem("wcBlockedPlayers");
  1630. var wasChanged = false;
  1631.  
  1632. try {
  1633. var parsedBlockedPlayers = JSON.parse(lsBlockedPlayers);
  1634. if (parsedBlockedPlayers === null) {
  1635. parsedBlockedPlayers = {}
  1636. }
  1637. }
  1638. catch {
  1639. var parsedBlockedPlayers = {};
  1640. wasChanged = true;
  1641. }
  1642.  
  1643. for (var name in parsedBlockedPlayers) {
  1644. const properties = parsedBlockedPlayers[name];
  1645. if (Array.isArray(properties)) {
  1646. var i = properties.length;
  1647. while (i--) {
  1648. const one = properties[i];
  1649. if (typeof one !== 'object'
  1650. || one === null
  1651. || !('until' in one)
  1652. || one.until < Date.now()
  1653. || ('colorId' in one && (!Number.isInteger(one.colorId) || one.colorId < 0 || one.colorId > 12))) {
  1654. properties.splice(i, 1);
  1655. wasChanged = true;
  1656. }
  1657. }
  1658. if (properties.length === 0) {
  1659. delete parsedBlockedPlayers[name];
  1660. wasChanged = true;
  1661. }
  1662. }
  1663. else {
  1664. delete parsedBlockedPlayers.name;
  1665. wasChanged = true;
  1666. }
  1667. }
  1668.  
  1669. wcFlags.wcBlockedPlayers = parsedBlockedPlayers;
  1670.  
  1671. if (saveIfChanged && wasChanged) {
  1672. wcSaveBlockedPlayers();
  1673. }
  1674. }
  1675.  
  1676. var wcReplacements = {}, wcRECompat, wcCompatibleReplace;
  1677.  
  1678. (function () {
  1679. var compatibleReplacements = {
  1680. "💔": ["</3"],
  1681. "😕": [":-/"],
  1682. "😢": [":'("],
  1683. "🙁": ["😟", ":("],
  1684. "❤️": ["<3"],
  1685. "😇": ["0:-)"],
  1686. "😂": [":'-)"],
  1687. "😗": [":*"],
  1688. "😐": [":|"],
  1689. "😮": [":-O"],
  1690. "😡": [":@"],
  1691. "🙂": ["😊", ":-)"],
  1692. "😄": [":D"],
  1693. "😭": [";("],
  1694. "😛": [":P"],
  1695. "😅": [",:-)"],
  1696. "😒": [":s"],
  1697. "😉": [";)"],
  1698. "🙃": ["🙂", "😊", "(-:"],
  1699. "🤐": ["🙊", ":secret:"],
  1700. "🕵️": ["👁", ":detective:"],
  1701. }
  1702.  
  1703. var testContext = document.createElement("canvas").getContext('2d');
  1704. function isEmojiAvailable(em) {
  1705. return testContext.measureText(em).width > 8;
  1706. }
  1707.  
  1708. for (var em in compatibleReplacements) {
  1709. if (!isEmojiAvailable(em)) {
  1710. for (var i = 0; i < compatibleReplacements[em].length; i++) {
  1711. if (i == compatibleReplacements[em].length - 1 || isEmojiAvailable(compatibleReplacements[em][i])) {
  1712. wcReplacements[em] = compatibleReplacements[em][i];
  1713. break;
  1714. }
  1715. }
  1716. }
  1717. }
  1718.  
  1719. testContext.canvas.remove();
  1720.  
  1721. if (Object.keys(wcReplacements).length > 0) {
  1722. wcRECompat = new RegExp(Object.keys(wcReplacements).join("|"), "gi");
  1723. wcCompatibleReplace = function (str) {
  1724. return str.replace(wcRECompat, function (matched) {
  1725. return wcReplacements[matched];
  1726. });
  1727. }
  1728. }
  1729. else {
  1730. wcReplacements = null;
  1731. wcCompatibleReplace = function (str) {
  1732. return str;
  1733. };
  1734. }
  1735. }());
  1736.  
  1737. var wcEmoticons = {
  1738. "</3": "💔",
  1739. "<\\\\3": "💔",
  1740. ":-/": "😕",
  1741. ":'-(": "😢",
  1742. ":'(": "😢",
  1743. ":(": "🙁",
  1744. ":-(": "🙁",
  1745. "<3": "❤️",
  1746. "O:-)": "😇",
  1747. "0:-)": "😇",
  1748. "O:)": "😇",
  1749. "0:)": "😇",
  1750. ":'-)": "😂",
  1751. ":')": "😂",
  1752. ":-*": "😗",
  1753. ":*": "😗",
  1754. ":-|": "😐",
  1755. ":|": "😐",
  1756. ":-O": "😮",
  1757. ":O": "😮",
  1758. ":@": "😡",
  1759. ":)": "🙂",
  1760. ":-)": "🙂",
  1761. "=)": "🙂",
  1762. "^^": "😄",
  1763. ":D": "😃",
  1764. ":-D": "😃",
  1765. "=D": "😃",
  1766. "XD": "😆",
  1767. ";(": "😭",
  1768. ":-P": "😛",
  1769. ":P": "😛",
  1770. ",:-)": "😅",
  1771. ":\$": "😒",
  1772. ":S": "😒",
  1773. ";-)": "😉",
  1774. ";)": "😉",
  1775. "(:": "🙃",
  1776. "(-:": "🙃",
  1777. "(=": "🙃",
  1778. ":F": "🐸",
  1779. "(F)": "🐸",
  1780. ":(|)": "🐸"
  1781. }
  1782.  
  1783. var wcEmRe = /(^|\\s)(['\\-\\\$\\(\\)*,/:;@\\\\\\^\\|<=03DOPSXF]{2,4})(\$|\\s)/gi;
  1784.  
  1785. function wcEmoticonsToEmoji(src) {
  1786. wcEmRe.lastIndex = 0;
  1787. var result = "",
  1788. prevIndex = 0,
  1789. REsult;
  1790. while (REsult = wcEmRe.exec(src)) {
  1791. if (REsult[2].toUpperCase() in wcEmoticons) {
  1792. if (REsult[1].length == 1) {
  1793. result += src.substring(prevIndex, REsult.index + 1) + wcEmoticons[REsult[2].toUpperCase()];
  1794. }
  1795. else {
  1796. result += wcEmoticons[REsult[2].toUpperCase()];
  1797. }
  1798.  
  1799. if (REsult[3].length != 0) {
  1800. wcEmRe.lastIndex -= 1;
  1801. }
  1802.  
  1803. prevIndex = wcEmRe.lastIndex;
  1804. }
  1805. else if (REsult[3].length != 0) {
  1806. wcEmRe.lastIndex -= 1;
  1807. }
  1808. }
  1809. result += src.substring(prevIndex);
  1810. return result;
  1811. }
  1812.  
  1813. document.body.addEventListener('keydown', function (e) {
  1814. if (e.keyCode == 13) {
  1815. if (playingAndReady) {
  1816. toggleChatInput();
  1817. }
  1818. }
  1819. else if (e.keyCode == 27) {
  1820. hideChatInput()
  1821. }
  1822. else if (e.keyCode == 67) {
  1823. toggleChat();
  1824. }
  1825. })
  1826.  
  1827. chatInput.addEventListener('focusout', function () {
  1828. chatInput.style.visibility = 'hidden';
  1829. });
  1830.  
  1831. chatInput.addEventListener('keydown', function (e) {
  1832. e.stopPropagation();
  1833. if (e.keyCode == 27) {
  1834. hideChatInput();
  1835. }
  1836. else if (e.keyCode == 13) {
  1837. if (chatInput.value.length == 0) {
  1838. hideChatInput();
  1839. }
  1840. else {
  1841. if (wsMsgSendStatus === 0) {
  1842. var message = wcFlags.wcConvertEmoticons ? strToHonkMsg(wcEmoticonsToEmoji(chatInput.value)) : strToHonkMsg(chatInput.value);
  1843. if (typeof (message) == "number") {
  1844. if (message == 0) {
  1845. wcNewNotification("Message length is 0");
  1846. }
  1847. else {
  1848. wcNewNotification(\`Shorten the message by about \${message - 186} characters\`, 5);
  1849. }
  1850. }
  1851. else {
  1852. wcSendMessage(message);
  1853. chatInput.value = "";
  1854. hideChatInput();
  1855. resizeChatInput();
  1856. }
  1857. }
  1858. else {
  1859. wcNewNotification("Please wait...", 2);
  1860. }
  1861. }
  1862. }
  1863. })
  1864.  
  1865. chatInput.addEventListener('keyup', function (e) {
  1866. e.stopPropagation();
  1867. })`
  1868.  
  1869. function waitPageReady(callback) {
  1870. if (typeof(getPlayer) != "function" && typeof(ddEl) != "object") {
  1871. requestAnimationFrame(function(){waitPageReady(callback)});
  1872. }
  1873. else {
  1874. setTimeout(callback,0);
  1875. }
  1876. }
  1877.  
  1878. function addScript() {
  1879. var template = document.createElement('script');
  1880. template.innerHTML = source;
  1881. document.body.appendChild(template);
  1882. }
  1883.  
  1884. waitPageReady(addScript);
  1885.  
  1886. })();