Wrong Chat

Just chat to chat with nearby players

当前为 2023-06-23 提交的版本,查看 最新版本

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

QingJ © 2025

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