Greasy Fork is available in English.

Lobbychat

lobbychat use commands and talk

  1. // ==UserScript==
  2. // @name Lobbychat
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-03-09
  5. // @description lobbychat use commands and talk
  6. // @author You
  7. // @match https://*.blooket.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=blooket.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. function reactHandler() {
  14. return Object.values(document.querySelector('body div[class*="_body"]'))[1].children[0]._owner
  15. }
  16. var j = 0;
  17. var rx = false;
  18. var hi = false;
  19. document.addEventListener("keydown", function(e) {
  20. if (e.key === "`") {
  21. hi = !hi;
  22. c.style.display = hi ? "block" : "none";
  23. }
  24. });
  25.  
  26. function parseCmd(t) {
  27. if (t.charAt(0) === "/") {
  28. var c = t.split(" ");
  29. var cm = c[0].replace("/", "");
  30. c.splice(0, 1);
  31. return {
  32. cmd: cm,
  33. args: c
  34. };
  35. } else {
  36. return false;
  37. }
  38. }
  39.  
  40. function setstate(args) {
  41. var t = {};
  42. args.forEach(e => {
  43. var p = e.split(":");
  44. if (!Number.isNaN(parseInt(p[1]))) {
  45. if (parseInt(p[1]).toString() === p[1]) {
  46. p[1] = parseInt(p[1]);
  47. }
  48. }
  49. t[p[0]] = p[1];
  50. });
  51. reactHandler().stateNode.setState(t);
  52. a("Set Successful!");
  53. }
  54.  
  55. function setv(args) {
  56. reactHandler().stateNode.props.liveGameController.setVal({
  57. path: "c/" + reactHandler().stateNode.props.client.name + "/" + args[0],
  58. val: args.slice(1, args.length).join(" ")
  59. });
  60. }
  61.  
  62. function tsvlog() {
  63. window.logsv = !window.logsv;
  64. a("SetVal log set to " + (window.logsv ? "Enabled" : "Disabled"));
  65. }
  66.  
  67. function dumpstate() {
  68. Object.keys(reactHandler().stateNode.state).map(e => {
  69. var obj = reactHandler().stateNode.state[e];
  70. if (obj != null) {
  71. if (Array.from(obj) && typeof obj === "object") {
  72. obj = "[Array]";
  73. }
  74. a(e + ":" + obj);
  75. } else {
  76. return "N/A";
  77. }
  78. }).join(";");
  79. }
  80.  
  81. function setBlook(b) {
  82. var blooks = webpackJsonp.push([
  83. [], {
  84. ['1234']: (_, a, b) => {
  85. a.webpack = b
  86. }
  87. },
  88. [
  89. ['1234']
  90. ]
  91. ]).webpack("MDrD").a;
  92. b = Object.keys(blooks).find(e => b.toLocaleLowerCase() === e.toLocaleLowerCase());
  93. if (blooks[b]) {
  94. a("Setting blook to " + b + "!");
  95. reactHandler().stateNode.props.liveGameController.setVal({
  96. id: reactHandler().stateNode.props.client.hostId,
  97. path: "c/" + reactHandler().stateNode.props.client.name,
  98. val: {
  99. b: b
  100. }
  101. });
  102. reactHandler().stateNode.props.client.blook = b;
  103. } else {
  104. a("No blook with that name was found!");
  105. }
  106. }
  107.  
  108. function unlockBlook(b) {
  109. var blooks = webpackJsonp.push([
  110. [], {
  111. ['1234']: (_, a, b) => {
  112. a.webpack = b
  113. }
  114. },
  115. [
  116. ['1234']
  117. ]
  118. ]).webpack("MDrD").a;
  119. b = Object.keys(blooks).find(e => b.toLocaleLowerCase() === e.toLocaleLowerCase());
  120. if (blooks[b]) {
  121. reactHandler().stateNode.state.unlocks.push(b);
  122. reactHandler().stateNode.forceUpdate();
  123. } else {
  124. a("No blook with that name was found!");
  125. }
  126. }
  127.  
  128. function list() {
  129. reactHandler().stateNode.props.liveGameController.getDatabaseVal("c").then(e => {
  130. a("Current Players(" + Object.keys(e).length + "): " + Object.keys(e).join(","));
  131. });
  132. }
  133.  
  134. function flist(p) {
  135. reactHandler().stateNode.props.liveGameController.getDatabaseVal("c/" + p).then(e => {
  136. if (e != null) {
  137. a("Dump: " + JSON.stringify(e));
  138. } else {
  139. a("Player not found!");
  140. }
  141. });
  142. }
  143.  
  144. function sendMessage(e) {
  145. var t = parseCmd(e);
  146. if (t) {
  147. switch (t.cmd) {
  148. case "cb":
  149. setBlook(t.args.join(" "));
  150. break;
  151. case "clear":
  152. b.innerHTML = "";
  153. break;
  154. case "dumpstate":
  155. dumpstate();
  156. break;
  157. case "list":
  158. list();
  159. break;
  160. case "tlog":
  161. tsvlog();
  162. break;
  163. case "setval":
  164. setv(t.args);
  165. break;
  166. case "setstate":
  167. setstate(t.args);
  168. break;
  169. case "ahelp":
  170. a("Advanced Commands: setval(sets val logged by tlog ex /setval b Chicken), tlog(toggles setval log), dumpstate(dumps react state),setstate(sets react state /setstate crypto:5 crypto2:5 etc)");
  171. break;
  172. case "help":
  173. a("Available Commands: help(gives help),ahelp(advanced commands help), cb(changes blook /cb cow), list(lists players connected), dump(dumps all available info about a player, passwords, etc(/dump player)), clear(clears chat), code(gives game code), unlock(unlocks blook on lobby screen)");
  174. break;
  175. case "dump":
  176. flist(t.args.join(" "));
  177. break;
  178. case "unlock":
  179. unlockBlook(t.args.join(" "));
  180. break;
  181. case "code":
  182. a("Game Code: " + reactHandler().stateNode.props.client.hostId);
  183. break;
  184. default:
  185. a("Unrecognized chat command!");
  186. break;
  187. }
  188. } else {
  189. reactHandler().stateNode.props.liveGameController.setVal({
  190. id: reactHandler().stateNode.props.client.hostId,
  191. path: "c/" + reactHandler().stateNode.props.client.name,
  192. val: {
  193. b: reactHandler().stateNode.props.client.blook,
  194. i: j,
  195. msg: e
  196. }
  197. }), j++;
  198. }
  199. }
  200. const c = document.createElement("div");
  201. c.className = "chat-box", document.body.appendChild(c);
  202. const h = document.createElement("div");
  203. h.className = "chat-header", h.textContent = "Chat", c.appendChild(h);
  204. const b = document.createElement("div");
  205. b.className = "chat-body", c.appendChild(b);
  206. const i = document.createElement("input");
  207.  
  208. function a(e) {
  209. const t = document.createElement("div");
  210. t.textContent = e, b.appendChild(t)
  211. }
  212. i.type = "text", i.className = "chat-input", i.placeholder = "Type a message...", c.appendChild(i), c.style.position = "fixed", c.style.bottom = "20px", c.style.right = "20px", c.style.width = "300px", c.style.backgroundColor = "#fff", c.style.border = "1px solid #ccc", c.style.boxShadow = "0px 0px 10px rgba(0, 0, 0, 0.2)", h.addEventListener("click", (() => {
  213. b.classList.toggle("open")
  214. })), i.addEventListener("keydown", (function(e) {
  215. 13 === e.keyCode && (sendMessage(e.srcElement.value), e.srcElement.value = "")
  216. }));
  217. var da = reactHandler().stateNode.props.liveGameController._liveApp.database()._delegate._repoInternal.server_.onDataUpdate_;
  218.  
  219. function handleChat(e, t) {
  220. if (e.includes("/stg") && !rx) {
  221. rx = true;
  222. a("Game has progressed! The Chat will not work, but commands will.");
  223. }
  224. if (t != null) {
  225. t.msg && (console.log(t.msg), a(e.split("/")[2] + ": " + t.msg))
  226. }
  227. }
  228. reactHandler().stateNode.props.liveGameController._liveApp.database()._delegate._repoInternal.server_.onDataUpdate_ = function(e, t, a, n) {
  229. console.log(e, t, a, n), handleChat(e, t), da(e, t, a, n)
  230. };
  231. window.logsv = false;
  232.  
  233. function onsv(e) {
  234. if (window.logsv) {
  235. a("Path: " + e.path.split("/").splice(2, 2).join("/") + " Val: " + ((typeof e.val === 'object') ? JSON.stringify(e.val) : e.val));
  236. }
  237. }
  238. var orgsv = reactHandler().stateNode.props.liveGameController.setVal;
  239. reactHandler().stateNode.props.liveGameController.setVal = function() {
  240. onsv.apply(this, arguments);
  241. orgsv.apply(this, arguments);
  242. };
  243. a("Lobbychat successfully loaded!");
  244.  
  245. function app() {
  246. c.style.wordWrap = "break-word";
  247. }
  248. app();