Bonk Panel

Have a better UI interface!

安装此脚本?
作者推荐脚本

您可能也喜欢Bonk Deobfuscator

安装此脚本
  1. // ==UserScript==
  2. // @name Bonk Panel
  3. // @version 0.4.2
  4. // @author KOOKY WARIROR
  5. // @description Have a better UI interface!
  6. // @match https://bonk.io/gameframe-release.html
  7. // @icon https://bonk.io/graphics/tt/favicon-32x32.png
  8. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/split.js/1.6.5/split.min.js
  10. // @license MIT
  11. // @namespace https://greasyfork.org/users/999838
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. /*
  16. Features
  17. ---------------------
  18. - Command Helper (type "/" and it will show up)
  19. - Show scores and rounds to win when in game
  20. - Show system chat in game
  21. - Show players in game
  22. - Import skin
  23. - Image overlay
  24. - Choose Hex Colour (Skin Editor)
  25.  
  26. And more...
  27. (discover it urself🕵️‍♀️)
  28. */
  29.  
  30. // SKINS
  31. class BYTEBUFFER {
  32. constructor() {
  33. this.index = 0
  34. this.buffer = new ArrayBuffer(102400)
  35. this.view = new DataView(this.buffer)
  36. this.implicitClassAliasArray = []
  37. this.implicitStringArray = []
  38. this.bodgeCaptureZoneDataIdentifierArray = []
  39. }
  40. readByte() {
  41. let returnval = this.view.getUint8(this.index)
  42. this.index += 1
  43. return returnval
  44. }
  45. writeByte(val) {
  46. this.view.setUint8(this.index, val)
  47. this.index += 1
  48. }
  49. readInt() {
  50. let returnval = this.view.getInt32(this.index)
  51. this.index += 4
  52. return returnval
  53. }
  54. writeInt(val) {
  55. this.view.setInt32(this.index, val)
  56. this.index += 4
  57. }
  58. readShort() {
  59. let returnval = this.view.getInt16(this.index)
  60. this.index += 2
  61. return returnval
  62. }
  63. writeShort(val) {
  64. this.view.setInt16(this.index, val)
  65. this.index += 2
  66. }
  67. readBoolean() {
  68. return this.readByte() == 1
  69. }
  70. writeBoolean(val) {
  71. if (val) {
  72. this.writeByte(1)
  73. } else {
  74. this.writeByte(0)
  75. }
  76. }
  77. readFloat() {
  78. let returnval = this.view.getFloat32(this.index)
  79. this.index += 4
  80. return returnval
  81. }
  82. writeFloat(val) {
  83. this.view.setFloat32(this.index, val)
  84. this.index += 4
  85. }
  86. toBase64() {
  87. let tmpstring = ""
  88. let tmparray = new Uint8Array(this.buffer)
  89. for (let i = 0; i < this.index; i++) {
  90. tmpstring += String.fromCharCode(tmparray[i])
  91. }
  92. return window.btoa(tmpstring)
  93. }
  94. fromBase64(val1, val2) {
  95. let tmpatob = window.atob(val1)
  96. let tmplength = tmpatob.length
  97. let tmparray = new Uint8Array(tmplength)
  98. for (let i = 0; i < tmplength; i++) {
  99. tmparray[i] = tmpatob.charCodeAt(i)
  100. }
  101. if (val2 === true) {
  102. tmparray = window.pako.inflate(tmparray)
  103. }
  104. this.buffer = tmparray.buffer.slice(tmparray.byteOffset, tmparray.byteLength + tmparray.byteOffset)
  105. this.view = new DataView(this.buffer)
  106. this.index = 0
  107. }
  108. }
  109. class AVATAR {
  110. constructor() {
  111. this.layers = []
  112. this.bc = 4492031
  113. }
  114. randomBC(val) {
  115. this.bc = val.colors[Math.floor(Math.random() * val.colors.length)]
  116. }
  117. makeSafe() {
  118. if (!(this.bc >= 0 && this.bc <= 16777215)) {
  119. this.bc = 4492031
  120. }
  121. for (let i = 0; i < this.layers.length; i++) {
  122. let layer = this.layers[i]
  123. if (layer) {
  124. if (!(layer.id >= 1 && layer.id <= 115)) {
  125. layer.id = 1
  126. }
  127. if (!(layer.x >= -99999 && layer.x <= 99999)) {
  128. layer.x = 0
  129. }
  130. if (!(layer.y >= -99999 && layer.y <= 99999)) {
  131. layer.y = 0
  132. }
  133. if (!(layer.scale >= -10 && layer.scale <= 10)) {
  134. layer.scale = 0.25
  135. }
  136. if (!(layer.angle >= -9999 && layer.angle <= 9999)) {
  137. layer.angle = 0
  138. }
  139. if (typeof layer.flipX != "boolean") {
  140. layer.flipX = false
  141. }
  142. if (typeof layer.flipY != "boolean") {
  143. layer.flipY = false
  144. }
  145. if (!(layer.color >= 0 && layer.color <= 16777215)) {
  146. layer.color = 0
  147. }
  148. }
  149. }
  150. for (let i = 0; i < this.layers.length; i++) {
  151. if (this.layers[i] == null) {
  152. this.layers.splice(i, 1)
  153. i--
  154. }
  155. }
  156. }
  157. fromObject(val) {
  158. if (val) {
  159. if (val.layers && typeof val.layers == "object" && val.layers.length >= 0 && val.layers.length <= 16) {
  160. this.layers = val.layers
  161. }
  162. this.bc = val.bc
  163. }
  164. this.makeSafe()
  165. }
  166. toString() {
  167. let tmpbuffer = new BYTEBUFFER()
  168. tmpbuffer.writeByte(10)
  169. tmpbuffer.writeByte(7)
  170. tmpbuffer.writeByte(3)
  171. tmpbuffer.writeByte(97)
  172. tmpbuffer.writeShort(2)
  173. tmpbuffer.writeByte(9)
  174. tmpbuffer.writeByte(this.layers.length * 2 + 1)
  175. tmpbuffer.writeByte(1)
  176. for (let i = 0; i < this.layers.length; i++) {
  177. let layer = this.layers[i]
  178. tmpbuffer.writeByte(10)
  179. if (i == 0) {
  180. tmpbuffer.writeByte(7)
  181. tmpbuffer.writeByte(5)
  182. tmpbuffer.writeByte(97)
  183. tmpbuffer.writeByte(108)
  184. } else {
  185. tmpbuffer.writeByte(5)
  186. }
  187. tmpbuffer.writeShort(1)
  188. tmpbuffer.writeShort(layer.id)
  189. tmpbuffer.writeFloat(layer.scale)
  190. tmpbuffer.writeFloat(layer.angle)
  191. tmpbuffer.writeFloat(layer.x)
  192. tmpbuffer.writeFloat(layer.y)
  193. tmpbuffer.writeBoolean(layer.flipX)
  194. tmpbuffer.writeBoolean(layer.flipY)
  195. tmpbuffer.writeInt(layer.color)
  196. }
  197. tmpbuffer.writeInt(this.bc)
  198. return encodeURIComponent(tmpbuffer.toBase64())
  199. }
  200. fromString(val) {
  201. if (val == "") {
  202. return
  203. }
  204. try {
  205. let tmpdecoded = decodeURIComponent(val)
  206. let tmpbuffer = new BYTEBUFFER()
  207. tmpbuffer.fromBase64(tmpdecoded)
  208. function tmpfunction(functionval) {
  209. var P5t = [arguments]
  210. let tmpobj = {}
  211. if (functionval.readByte().toString(16) == "a") {
  212. if (functionval.readByte() == 7) {
  213. functionval.readByte()
  214. functionval.readByte()
  215. functionval.readByte()
  216. } else {
  217. }
  218. P5t[3] = functionval.readShort()
  219. tmpobj.id = functionval.readShort()
  220. tmpobj.scale = functionval.readFloat()
  221. tmpobj.angle = functionval.readFloat()
  222. tmpobj.x = functionval.readFloat()
  223. tmpobj.y = functionval.readFloat()
  224. tmpobj.flipX = functionval.readBoolean()
  225. tmpobj.flipY = functionval.readBoolean()
  226. tmpobj.color = functionval.readInt()
  227. } else {
  228. tmpobj = null
  229. }
  230. return tmpobj
  231. }
  232. let tmpbyte = tmpbuffer.readByte()
  233. let tmpbyte2 = tmpbuffer.readByte()
  234. let tmpbyte3 = tmpbuffer.readByte()
  235. let tmpbyte4 = tmpbuffer.readByte()
  236. let tmpbyte5 = tmpbuffer.readByte()
  237. let tmpbyteover2 = (tmpbuffer.readByte() - 1) / 2
  238. let tmpbyte6 = tmpbuffer.readByte()
  239. while (tmpbyte6 != 1) {
  240. let tmpnumber = 0
  241. if (tmpbyte6 == 3) {
  242. tmpnumber = tmpbuffer.readByte() - 48
  243. } else {
  244. if (tmpbyte6 == 5) {
  245. tmpnumber = (tmpbuffer.readByte() - 48) * 10 + (tmpbuffer.readByte() - 48)
  246. }
  247. }
  248. this.layers[tmpnumber] = tmpfunction(tmpbuffer)
  249. tmpbyte6 = tmpbuffer.readByte()
  250. }
  251. for (let i = 0; i < tmpbyteover2; i++) {
  252. this.layers[i] = tmpfunction(tmpbuffer)
  253. }
  254. if (tmpbuffer.readShort() >= 2) {
  255. this.bc = tmpbuffer.readInt()
  256. }
  257. this.makeSafe()
  258. } catch (M8n) {
  259. this.layers = []
  260. this.bc = 4492031
  261. }
  262. }
  263. }
  264. fetch("https://raw.githubusercontent.com/kookywarrior/bonkio-skins/main/skins.js")
  265. .then((response) => response.text())
  266. .then((response) => {
  267. eval(response)
  268. })
  269. .catch((err) => console.log(err))
  270.  
  271. // REMOVE ANNOYING STUFF
  272. function removeEleByID(id) {
  273. let e = window.top.document.getElementById(id)
  274. if (e !== null) e.remove()
  275. }
  276. removeEleByID("descriptioncontainer")
  277. removeEleByID("bonk_d_1")
  278. removeEleByID("bonk_d_2")
  279. window.top.document.body.getElementsByTagName("style")[0].innerHTML += `
  280. #maingameframe { margin: 0 !important; margin-top: 0 !important; }
  281. #adboxverticalleftCurse { display: none !important; }
  282. #adboxverticalCurse { display: none !important; }
  283. #bonkioheader { display: none !important; }
  284. body { overflow: hidden !important; }`
  285.  
  286. // FIX CHAT STUFF
  287. function hideEleByID(id) {
  288. let e = document.getElementById(id)
  289. if (e !== null) e.hidden = true
  290. }
  291. hideEleByID("newbonklobby_chat_lowerline")
  292. hideEleByID("newbonklobby_chat_lowerinstruction")
  293. hideEleByID("ingamechatbox")
  294. hideEleByID("newbonklobby_chat_content")
  295. document.getElementById("newbonklobby_chat_content").style.height = "calc(100% - 36px)"
  296. document.body.appendChild(document.getElementById("newbonklobby_chat_input"))
  297. document.body.appendChild(document.getElementById("ingamechatinputtext"))
  298. document.getElementById("newbonklobby_chatbox").getElementsByClassName("newbonklobby_boxtop newbonklobby_boxtop_classic")[0].textContent =
  299. "More Coming Soon..."
  300.  
  301. // APPEND FPS TO TOP BAR
  302. const FPS = document.createElement("div")
  303. FPS.innerText = 0
  304. FPS.style = `color: var(--bonk_theme_top_bar_text, #ffffff8f) !important;font-family:"futurept_b1";line-height:35px;display:inline-block;padding-left:15px;padding-right:15px;`
  305. FPS.className = "niceborderright"
  306. document.getElementById("pretty_top_bar").appendChild(FPS)
  307. function fpsUpdate() {
  308. const updateDelay = 500
  309. let lastFpsUpdate = 0
  310. let frames = 0
  311. function updateFPS() {
  312. let now = Date.now()
  313. let elapsed = now - lastFpsUpdate
  314. if (elapsed < updateDelay) {
  315. ++frames
  316. } else {
  317. FPS.innerText = `${Math.round(frames / (elapsed / 1000))} FPS`
  318. frames = 0
  319. lastFpsUpdate = now
  320. }
  321. window.requestAnimationFrame(updateFPS)
  322. }
  323. lastFpsUpdate = Date.now()
  324. window.requestAnimationFrame(updateFPS)
  325. }
  326. fpsUpdate()
  327.  
  328. // ADD MAIN CONTAINER
  329. const container = document.createElement("div")
  330. container.id = "bonkpanelcontainer"
  331. document.getElementById("pagecontainer").insertBefore(container, document.getElementById("xpbarcontainer"))
  332. container.appendChild(document.getElementById("bonkiocontainer"))
  333.  
  334. // ADD PANEL CONTAINER
  335. const panelLeft = document.createElement("div")
  336. panelLeft.style.visibility = "hidden"
  337. panelLeft.className = "panelcontainer"
  338. container.insertBefore(panelLeft, document.getElementById("bonkiocontainer"))
  339. const panelRight = document.createElement("div")
  340. panelRight.style.visibility = "hidden"
  341. panelRight.className = "panelcontainer"
  342. container.appendChild(panelRight)
  343.  
  344. // ADD PANELS
  345. for (let index = 1; index < 5; index++) {
  346. const panel = document.createElement("div")
  347. panel.id = `panel${index}`
  348. panel.className = "panel"
  349. const injectTO = index % 2 == 0 ? panelRight : panelLeft
  350. injectTO.appendChild(panel)
  351. }
  352. let leftSize = localStorage.getItem("panel-left-size") ? JSON.parse(localStorage.getItem("panel-left-size")) : [40, 60]
  353. let rightSize = localStorage.getItem("panel-right-size") ? JSON.parse(localStorage.getItem("panel-right-size")) : [40, 60]
  354. let leftSplit, rightSplit
  355. setTimeout(() => {
  356. leftSplit = Split(["#panel1", "#panel3"], {
  357. sizes: leftSize,
  358. direction: "vertical",
  359. gutterSize: 15,
  360. snapOffset: 0,
  361. onDragEnd: function (e) {
  362. localStorage.setItem("panel-left-size", JSON.stringify(e))
  363. }
  364. })
  365. rightSplit = Split(["#panel2", "#panel4"], {
  366. sizes: rightSize,
  367. direction: "vertical",
  368. gutterSize: 15,
  369. snapOffset: 0,
  370. onDragEnd: function (e) {
  371. localStorage.setItem("panel-right-size", JSON.stringify(e))
  372. }
  373. })
  374. }, 0)
  375.  
  376. // ADD COMMAND PANEL
  377. let haveWS = false
  378. const commandContainer = document.createElement("div")
  379. commandContainer.id = "commandcontainer"
  380. commandContainer.style.display = "none"
  381. const commandBackground = document.createElement("div")
  382. commandBackground.id = "commandbackground"
  383. commandContainer.appendChild(commandBackground)
  384. const commandWindow = document.createElement("div")
  385. commandWindow.id = "commandpanel"
  386. commandWindow.classList.add("windowShadow")
  387. const commandTopBar = document.createElement("div")
  388. commandTopBar.className = "newbonklobby_boxtop newbonklobby_boxtop_classic"
  389. commandTopBar.textContent = "Command Helper"
  390. commandWindow.appendChild(commandTopBar)
  391. const commandListContainer = document.createElement("div")
  392. commandListContainer.id = "commandlistcontainer"
  393. commandListContainer.className = "chatcontainer"
  394. commandWindow.appendChild(commandListContainer)
  395. commandContainer.appendChild(commandWindow)
  396. document.getElementById("bonkiocontainer").appendChild(commandContainer)
  397. let COMMANDS = {
  398. kick: (id) => {
  399. if (ROOM_VAR.quick) {
  400. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  401. return
  402. }
  403. id = parseInt(id)
  404. if (id == null || typeof id != "number") {
  405. FUNCTIONS.showSystemMessage("Failed, playerID not found", "#b53030")
  406. return
  407. }
  408. if (ROOM_VAR.myID == id) {
  409. FUNCTIONS.showSystemMessage("Failed, you can't use this command to yourself", "#b53030")
  410. return
  411. }
  412. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  413. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  414. return
  415. }
  416. if (ROOM_VAR.players[id] == null) {
  417. FUNCTIONS.showSystemMessage("Failed, player not found in this room", "#b53030")
  418. return
  419. }
  420. iosend([
  421. 9,
  422. {
  423. banshortid: id,
  424. kickonly: true
  425. }
  426. ])
  427. },
  428. ban: (id) => {
  429. if (ROOM_VAR.quick) {
  430. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  431. return
  432. }
  433. id = parseInt(id)
  434. if (id == null || typeof id != "number") {
  435. FUNCTIONS.showSystemMessage("Failed, playerID not found", "#b53030")
  436. return
  437. }
  438. if (ROOM_VAR.myID == id) {
  439. FUNCTIONS.showSystemMessage("Failed, you can't use this command to yourself", "#b53030")
  440. return
  441. }
  442. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  443. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  444. return
  445. }
  446. if (ROOM_VAR.players[id] == null) {
  447. FUNCTIONS.showSystemMessage("Failed, player not found in this room", "#b53030")
  448. return
  449. }
  450. iosend([
  451. 9,
  452. {
  453. banshortid: id,
  454. kickonly: false
  455. }
  456. ])
  457. },
  458. mute: (id) => {
  459. id = parseInt(id)
  460. if (id == null || typeof id != "number") {
  461. FUNCTIONS.showSystemMessage("Failed, playerID not found", "#b53030")
  462. return
  463. }
  464. if (ROOM_VAR.myID == id) {
  465. FUNCTIONS.showSystemMessage("Failed, you can't use this command to yourself", "#b53030")
  466. return
  467. }
  468. if (ROOM_VAR.players[id] == null) {
  469. FUNCTIONS.showSystemMessage("Failed, player not found in this room", "#b53030")
  470. return
  471. }
  472. ROOM_VAR.players[id].mute = true
  473. PROCESSCOMMAND(`/mute '${ROOM_VAR.players[id].userName}'`)
  474. },
  475. unmute: (id) => {
  476. id = parseInt(id)
  477. if (id == null || typeof id != "number") {
  478. FUNCTIONS.showSystemMessage("Failed, playerID not found", "#b53030")
  479. return
  480. }
  481. if (ROOM_VAR.myID == id) {
  482. FUNCTIONS.showSystemMessage("Failed, you can't use this command to yourself", "#b53030")
  483. return
  484. }
  485. if (ROOM_VAR.players[id] == null) {
  486. FUNCTIONS.showSystemMessage("Failed, player not found in this room", "#b53030")
  487. return
  488. }
  489. ROOM_VAR.players[id].mute = false
  490. PROCESSCOMMAND(`/unmute '${ROOM_VAR.players[id].userName}'`)
  491. },
  492. balance: (id, size) => {
  493. if (ROOM_VAR.quick) {
  494. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  495. return
  496. }
  497. id = parseInt(id)
  498. size = parseInt(size)
  499. if (id == null || typeof id != "number") {
  500. FUNCTIONS.showSystemMessage("Failed, playerID not found", "#b53030")
  501. return
  502. }
  503. if (size == null || typeof size != "number") {
  504. FUNCTIONS.showSystemMessage("Failed, size not found", "#b53030")
  505. return
  506. }
  507. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  508. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  509. return
  510. }
  511. if (ROOM_VAR.players[id] == null) {
  512. FUNCTIONS.showSystemMessage("Failed, player not found in this room", "#b53030")
  513. return
  514. }
  515. if (size < -100 || size > 100) {
  516. FUNCTIONS.showSystemMessage("Failed, size must be between -100 and 100", "#b53030")
  517. return
  518. }
  519. iosend([
  520. 29,
  521. {
  522. sid: id,
  523. bal: size
  524. }
  525. ])
  526. },
  527. balanceall: (size) => {
  528. if (ROOM_VAR.quick) {
  529. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  530. return
  531. }
  532. size = parseInt(size)
  533. if (size == null || typeof size != "number") {
  534. FUNCTIONS.showSystemMessage("Failed, size not found", "#b53030")
  535. return
  536. }
  537. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  538. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  539. return
  540. }
  541. if (size < -100 || size > 100) {
  542. FUNCTIONS.showSystemMessage("Failed, size must be between -100 and 100", "#b53030")
  543. return
  544. }
  545. for (let i = 0; i < ROOM_VAR.players.length; i++) {
  546. const element = ROOM_VAR.players[i]
  547. if (element == null) continue
  548. iosend([
  549. 29,
  550. {
  551. sid: i,
  552. bal: size
  553. }
  554. ])
  555. }
  556. },
  557. roomname: (name) => {
  558. if (ROOM_VAR.quick) {
  559. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  560. return
  561. }
  562. if (!name) {
  563. FUNCTIONS.showSystemMessage("Failed, name not found", "#b53030")
  564. return
  565. }
  566. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  567. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  568. return
  569. }
  570. iosend([
  571. 52,
  572. {
  573. newName: name
  574. }
  575. ])
  576. },
  577. roompass: (password) => {
  578. if (ROOM_VAR.quick) {
  579. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  580. return
  581. }
  582. if (!password) {
  583. FUNCTIONS.showSystemMessage("Failed, password not found", "#b53030")
  584. return
  585. }
  586. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  587. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  588. return
  589. }
  590. iosend([
  591. 53,
  592. {
  593. newPass: password
  594. }
  595. ])
  596. },
  597. clearroompass: () => {
  598. if (ROOM_VAR.quick) {
  599. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  600. return
  601. }
  602. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  603. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  604. return
  605. }
  606. iosend([
  607. 53,
  608. {
  609. newPass: ""
  610. }
  611. ])
  612. },
  613. move: (id, teamid) => {
  614. if (ROOM_VAR.quick) {
  615. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  616. return
  617. }
  618. id = parseInt(id)
  619. teamid = parseInt(teamid)
  620. if (id == null || typeof id != "number") {
  621. FUNCTIONS.showSystemMessage("Failed, playerID not found", "#b53030")
  622. return
  623. }
  624. if (teamid == null || typeof teamid != "number") {
  625. FUNCTIONS.showSystemMessage("Failed, teamID not found", "#b53030")
  626. return
  627. }
  628. if (![0, 1, 2, 3, 4, 5].includes(teamid)) {
  629. FUNCTIONS.showSystemMessage("Failed, team not found", "#b53030")
  630. return
  631. }
  632. if (ROOM_VAR.players[id] == null) {
  633. FUNCTIONS.showSystemMessage("Failed, player not found in this room", "#b53030")
  634. return
  635. }
  636. if (id == ROOM_VAR.myID) {
  637. iosend([
  638. 6,
  639. {
  640. targetTeam: teamid
  641. }
  642. ])
  643. } else if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  644. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  645. return
  646. } else {
  647. iosend([
  648. 26,
  649. {
  650. targetID: id,
  651. targetTeam: teamid
  652. }
  653. ])
  654. }
  655. if (ROOM_VAR.myID == ROOM_VAR.hostID) {
  656. if (teamid < 0) {
  657. ROOM_VAR.stateFunction.hostHandlePlayerJoined(id, ROOM_VAR.players.length, teamid)
  658. } else {
  659. ROOM_VAR.stateFunction.hostHandlePlayerLeft(id)
  660. }
  661. }
  662. },
  663. moveall: (teamid) => {
  664. if (ROOM_VAR.quick) {
  665. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  666. return
  667. }
  668. teamid = parseInt(teamid)
  669. if (teamid == null || typeof teamid != "number") {
  670. FUNCTIONS.showSystemMessage("Failed, teamID not found", "#b53030")
  671. return
  672. }
  673. if (![0, 1, 2, 3, 4, 5].includes(teamid)) {
  674. FUNCTIONS.showSystemMessage("Failed, team not found", "#b53030")
  675. return
  676. }
  677. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  678. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  679. return
  680. }
  681. for (let i = 0; i < ROOM_VAR.players.length; i++) {
  682. const element = ROOM_VAR.players[i]
  683. if (element == null) continue
  684. if (i == ROOM_VAR.myID) {
  685. iosend([
  686. 6,
  687. {
  688. targetTeam: teamid
  689. }
  690. ])
  691. } else {
  692. iosend([
  693. 26,
  694. {
  695. targetID: i,
  696. targetTeam: teamid
  697. }
  698. ])
  699. }
  700. if (teamid < 0) {
  701. ROOM_VAR.stateFunction.hostHandlePlayerJoined(i, ROOM_VAR.players.length, teamid)
  702. } else {
  703. ROOM_VAR.stateFunction.hostHandlePlayerLeft(i)
  704. }
  705. }
  706. },
  707. mode: (modeid) => {
  708. if (ROOM_VAR.quick) {
  709. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  710. return
  711. }
  712. modeid = modeid.replace(" ", "")
  713. if (!modeid) {
  714. FUNCTIONS.showSystemMessage("Failed, modeID not found", "#b53030")
  715. return
  716. }
  717. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  718. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  719. return
  720. }
  721. iosend([
  722. 20,
  723. {
  724. ga: modeid == "f" ? "f" : "b",
  725. mo: modeid
  726. }
  727. ])
  728. },
  729. team: (option) => {
  730. if (ROOM_VAR.quick) {
  731. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  732. return
  733. }
  734. option = option.replace(" ", "")
  735. if (!option) {
  736. FUNCTIONS.showSystemMessage("Failed, option not found", "#b53030")
  737. return
  738. }
  739. if (!["on", "off"].includes(option)) {
  740. FUNCTIONS.showSystemMessage("Failed, invalid option", "#b53030")
  741. return
  742. }
  743. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  744. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  745. return
  746. }
  747. iosend([
  748. 32,
  749. {
  750. t: option == "on" ? true : false
  751. }
  752. ])
  753. },
  754. lock: (option) => {
  755. if (ROOM_VAR.quick) {
  756. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  757. return
  758. }
  759. option = option.replace(" ", "")
  760. if (!option) {
  761. FUNCTIONS.showSystemMessage("Failed, option not found", "#b53030")
  762. return
  763. }
  764. if (!["on", "off"].includes(option)) {
  765. FUNCTIONS.showSystemMessage("Failed, invalid option", "#b53030")
  766. return
  767. }
  768. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  769. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  770. return
  771. }
  772. iosend([
  773. 7,
  774. {
  775. teamLock: option == "on" ? true : false
  776. }
  777. ])
  778. },
  779. skin: (id) => {
  780. id = parseInt(id)
  781. if (id == null || typeof id != "number") {
  782. FUNCTIONS.showSystemMessage("Failed, playerID not found", "#b53030")
  783. return
  784. }
  785. if (ROOM_VAR.players[id] == null) {
  786. FUNCTIONS.showSystemMessage("Failed, player not found in this room", "#b53030")
  787. return
  788. }
  789. const a = document.createElement("a")
  790. const file = new Blob([JSON.stringify(ROOM_VAR.players[id].avatar)], { type: "text/plain" })
  791. a.href = URL.createObjectURL(file)
  792. a.download = `avatar_${ROOM_VAR.players[id].userName}_${Date.now()}`
  793. a.click()
  794. },
  795. link: () => {
  796. if (ROOM_VAR.quick) {
  797. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  798. return
  799. }
  800. document.getElementById("newbonklobby_linkbutton").click()
  801. },
  802. start: () => {
  803. if (ROOM_VAR.quick) {
  804. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  805. return
  806. }
  807. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  808. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  809. return
  810. }
  811. STARTGAME()
  812. },
  813. round: (number) => {
  814. if (ROOM_VAR.quick) {
  815. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  816. return
  817. }
  818. number = parseInt(number)
  819. if (number == null || typeof number != "number") {
  820. FUNCTIONS.showSystemMessage("Failed, invalid number", "#b53030")
  821. return
  822. }
  823. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  824. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  825. return
  826. }
  827. iosend([
  828. 21,
  829. {
  830. w: number
  831. }
  832. ])
  833. },
  834. clear: () => {
  835. document.getElementById("messagecontainer").innerHTML = ""
  836. },
  837. clearsys: () => {
  838. document.getElementById("systemcontainer").innerHTML = ""
  839. },
  840. size: (option, topsize, bottomsize) => {
  841. option = option.replace(" ", "")
  842. topsize = parseInt(topsize)
  843. bottomsize = parseInt(bottomsize)
  844. if (!["left", "right"].includes(option)) {
  845. FUNCTIONS.showSystemMessage("Failed, invalid option", "#b53030")
  846. return
  847. }
  848. if (topsize == null || typeof topsize != "number" || bottomsize == null || typeof bottomsize != "number") {
  849. FUNCTIONS.showSystemMessage("Failed, invalid number", "#b53030")
  850. return
  851. }
  852. if (topsize + bottomsize != 100) {
  853. FUNCTIONS.showSystemMessage("Failed, the sum of top and bottom size must be 100", "#b53030")
  854. return
  855. }
  856. let sizes = [topsize, bottomsize]
  857. if (option == "left") {
  858. leftSplit.setSizes(sizes)
  859. localStorage.setItem("panel-left-size", JSON.stringify(sizes))
  860. } else {
  861. rightSplit.setSizes(sizes)
  862. localStorage.setItem("panel-right-size", JSON.stringify(sizes))
  863. }
  864. },
  865. fav: () => {
  866. PROCESSCOMMAND("/fav")
  867. },
  868. unfav: () => {
  869. PROCESSCOMMAND("/unfav")
  870. },
  871. givehost: (id) => {
  872. if (ROOM_VAR.quick) {
  873. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  874. return
  875. }
  876. id = parseInt(id)
  877. if (id == null || typeof id != "number") {
  878. FUNCTIONS.showSystemMessage("Failed, playerID not found", "#b53030")
  879. return
  880. }
  881. if (ROOM_VAR.myID == id) {
  882. FUNCTIONS.showSystemMessage("Failed, you can't use this command to yourself", "#b53030")
  883. return
  884. }
  885. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  886. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  887. return
  888. }
  889. if (ROOM_VAR.players[id] == null) {
  890. FUNCTIONS.showSystemMessage("Failed, player not found in this room", "#b53030")
  891. return
  892. }
  893. iosend([
  894. 34,
  895. {
  896. id: id
  897. }
  898. ])
  899. },
  900. countdown: (option) => {
  901. if (ROOM_VAR.quick) {
  902. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  903. return
  904. }
  905. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  906. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  907. return
  908. }
  909. option = option.replace(" ", "")
  910. if (!["1", "2", "3"].includes(option)) {
  911. FUNCTIONS.showSystemMessage("Failed, invalid option", "#b53030")
  912. return
  913. }
  914. iosend([36, { num: parseInt(option) }])
  915. },
  916. abort: () => {
  917. if (ROOM_VAR.quick) {
  918. FUNCTIONS.showSystemMessage("Failed, unavailable in quick play", "#b53030")
  919. return
  920. }
  921. if (ROOM_VAR.myID != ROOM_VAR.hostID) {
  922. FUNCTIONS.showSystemMessage("Failed, you must be room host", "#b53030")
  923. return
  924. }
  925. iosend([37])
  926. },
  927. xp: () => {
  928. FUNCTIONS.showSystemMessage(`${ROOM_VAR.xpEarned}xp earned`, "#0955c7")
  929. },
  930. earnxp: () => {
  931. iosend([38])
  932. },
  933. ready: (option) => {
  934. option = option.replace(" ", "")
  935. if (!["true", "false"].includes(option)) {
  936. FUNCTIONS.showSystemMessage("Failed, invalid option", "#b53030")
  937. return
  938. }
  939. iosend([16, { ready: option === "true" }])
  940. },
  941. zoom: (number) => {
  942. number = parseFloat(number)
  943. if (number == null || typeof number != "number") {
  944. FUNCTIONS.showSystemMessage("Failed, invalid number", "#b53030")
  945. return
  946. }
  947. scaler = number
  948. RESCALESTAGE()
  949. }
  950. }
  951. let SEARCH = {
  952. addInput: (addText = "", setInstead = false) => {
  953. if (addText == "") return
  954. if (setInstead) {
  955. document.getElementById("bonkpanelchatinput").value = addText
  956. } else {
  957. document.getElementById("bonkpanelchatinput").value += addText
  958. }
  959. FUNCTIONS.showCommandHelper(document.getElementById("bonkpanelchatinput").value)
  960. },
  961. remove: () => {
  962. commandListContainer.innerHTML = ""
  963. },
  964. commands: (filterText = "") => {
  965. SEARCH.remove()
  966. COMMANDLIST.forEach((e) => {
  967. if (!e.name.startsWith(filterText)) return
  968. if (ROOM_VAR.hostID != ROOM_VAR.myID && e.host) return
  969. if (ROOM_VAR.quick && e.noQuick) return
  970.  
  971. let params = ""
  972. e.param.forEach((a) => {
  973. params += ` <${a}>`
  974. })
  975.  
  976. const card = document.createElement("div")
  977. card.className = "windowShadow commandscardcontainer"
  978. card.addEventListener("click", () => {
  979. SEARCH.addInput("/" + e.name + " ", true)
  980. document.getElementById("bonkpanelchatinput").focus()
  981. })
  982. if (document.getElementById("bonkpanelchatinput").onkeydown == null) {
  983. document.getElementById("bonkpanelchatinput").onkeydown = function (event) {
  984. if (event.code == "Tab") {
  985. event.preventDefault()
  986. document.getElementById("bonkpanelchatinput").onkeydown = null
  987. SEARCH.addInput("/" + e.name + " ", true)
  988. document.getElementById("bonkpanelchatinput").focus()
  989. }
  990. }
  991. }
  992.  
  993. const title = document.createElement("div")
  994. title.className = "commandscardtitle"
  995. title.textContent = e.name + params
  996. card.appendChild(title)
  997.  
  998. const description = document.createElement("div")
  999. description.className = "commandscarddescription"
  1000. description.textContent = e.des
  1001. card.appendChild(description)
  1002.  
  1003. commandListContainer.appendChild(card)
  1004. })
  1005. },
  1006. players: (command) => {
  1007. SEARCH.remove()
  1008.  
  1009. for (let i = 0; i < ROOM_VAR.players.length; i++) {
  1010. if (command.withoutMe && i == ROOM_VAR.myID) continue
  1011. if (command.checkHost && ROOM_VAR.myID != ROOM_VAR.hostID && i != ROOM_VAR.myID) continue
  1012.  
  1013. const element = ROOM_VAR.players[i]
  1014. if (element == null) continue
  1015.  
  1016. const card = document.createElement("div")
  1017. card.className = "windowShadow commandscardcontainer"
  1018. card.style.flexDirection = "row"
  1019. card.addEventListener("click", () => {
  1020. SEARCH.addInput(i.toString() + " ")
  1021. document.getElementById("bonkpanelchatinput").focus()
  1022. })
  1023. if (document.getElementById("bonkpanelchatinput").onkeydown == null) {
  1024. document.getElementById("bonkpanelchatinput").onkeydown = function (event) {
  1025. if (event.code == "Tab") {
  1026. event.preventDefault()
  1027. document.getElementById("bonkpanelchatinput").onkeydown = null
  1028. SEARCH.addInput(i.toString() + " ")
  1029. document.getElementById("bonkpanelchatinput").focus()
  1030. }
  1031. }
  1032. }
  1033.  
  1034. const img = document.createElement("div")
  1035. img.classList.add("commandplayerimgcontainer")
  1036. card.appendChild(img)
  1037.  
  1038. const textcontainer = document.createElement("div")
  1039. textcontainer.style = `width: calc(100% - 100px); display: flex; flex-direction: column; justify-content: space-evenly`
  1040. const name = document.createElement("div")
  1041. name.className = "commandscardtitle"
  1042. name.textContent = element.userName
  1043. textcontainer.appendChild(name)
  1044. const id = document.createElement("div")
  1045. id.style.marginBottom = "0"
  1046. id.className = "commandscarddescription"
  1047. id.textContent = `ID: ${i.toString()}`
  1048. textcontainer.appendChild(id)
  1049. const levelorguest = document.createElement("div")
  1050. levelorguest.className = "commandscarddescription"
  1051. levelorguest.textContent = element.guest ? "Guest" : `Level ${element.level}`
  1052. textcontainer.appendChild(levelorguest)
  1053. card.appendChild(textcontainer)
  1054. commandListContainer.appendChild(card)
  1055. if (ROOM_VAR.commandAvatarCache[element.userName] && ROOM_VAR.commandAvatarCache[element.userName][1]) {
  1056. img.appendChild(ROOM_VAR.commandAvatarCache[element.userName][1].cloneNode(true))
  1057. } else {
  1058. try {
  1059. FUNCTIONS.createAvatarImage(element.avatar, 1, img, "newbonklobby_chat_msg_avatar", 100, 100, ROOM_VAR.commandAvatarCache, i, 1, 1, 0.25)
  1060. } catch (error) {
  1061. console.error(error)
  1062. }
  1063. }
  1064. }
  1065. },
  1066. teams: () => {
  1067. SEARCH.remove()
  1068.  
  1069. Array.from([
  1070. ["Spectate", 0],
  1071. ["Free for all", 1],
  1072. ["Red", 2],
  1073. ["Blue", 3],
  1074. ["Green", 4],
  1075. ["Yellow", 5]
  1076. ]).forEach((e) => {
  1077. const card = document.createElement("div")
  1078. card.className = "windowShadow commandscardcontainer"
  1079. card.addEventListener("click", () => {
  1080. SEARCH.addInput(e[1].toString() + " ")
  1081. document.getElementById("bonkpanelchatinput").focus()
  1082. })
  1083. if (document.getElementById("bonkpanelchatinput").onkeydown == null) {
  1084. document.getElementById("bonkpanelchatinput").onkeydown = function (event) {
  1085. if (event.code == "Tab") {
  1086. event.preventDefault()
  1087. document.getElementById("bonkpanelchatinput").onkeydown = null
  1088. SEARCH.addInput(e[1].toString() + " ")
  1089. document.getElementById("bonkpanelchatinput").focus()
  1090. }
  1091. }
  1092. }
  1093. const title = document.createElement("div")
  1094. title.className = "commandscardtitle"
  1095. title.textContent = e[0]
  1096. card.appendChild(title)
  1097. const id = document.createElement("div")
  1098. id.className = "commandscarddescription"
  1099. id.textContent = "ID: " + e[1].toString()
  1100. card.appendChild(id)
  1101. commandListContainer.appendChild(card)
  1102. })
  1103. },
  1104. modes: () => {
  1105. SEARCH.remove()
  1106.  
  1107. Array.from([
  1108. ["Classic", "b"],
  1109. ["Arrows", "ar"],
  1110. ["Death arrows", "ard"],
  1111. ["Grapple", "sp"],
  1112. ["Football", "f"],
  1113. ["VTOL", "v"]
  1114. ]).forEach((e) => {
  1115. const card = document.createElement("div")
  1116. card.className = "windowShadow commandscardcontainer"
  1117. card.addEventListener("click", () => {
  1118. SEARCH.addInput(e[1].toString() + " ")
  1119. document.getElementById("bonkpanelchatinput").focus()
  1120. })
  1121. if (document.getElementById("bonkpanelchatinput").onkeydown == null) {
  1122. document.getElementById("bonkpanelchatinput").onkeydown = function (event) {
  1123. if (event.code == "Tab") {
  1124. event.preventDefault()
  1125. document.getElementById("bonkpanelchatinput").onkeydown = null
  1126. SEARCH.addInput(e[1].toString() + " ")
  1127. document.getElementById("bonkpanelchatinput").focus()
  1128. }
  1129. }
  1130. }
  1131. const title = document.createElement("div")
  1132. title.className = "commandscardtitle"
  1133. title.textContent = e[0]
  1134. card.appendChild(title)
  1135. const id = document.createElement("div")
  1136. id.className = "commandscarddescription"
  1137. id.textContent = "ID: " + e[1].toString()
  1138. card.appendChild(id)
  1139. commandListContainer.appendChild(card)
  1140. })
  1141. },
  1142. option: (command) => {
  1143. SEARCH.remove()
  1144.  
  1145. Array.from(command.option).forEach((e) => {
  1146. const card = document.createElement("div")
  1147. card.className = "windowShadow commandscardcontainer"
  1148. card.addEventListener("click", () => {
  1149. SEARCH.addInput(e + " ")
  1150. document.getElementById("bonkpanelchatinput").focus()
  1151. })
  1152. if (document.getElementById("bonkpanelchatinput").onkeydown == null) {
  1153. document.getElementById("bonkpanelchatinput").onkeydown = function (event) {
  1154. if (event.code == "Tab") {
  1155. event.preventDefault()
  1156. document.getElementById("bonkpanelchatinput").onkeydown = null
  1157. SEARCH.addInput(e + " ")
  1158. document.getElementById("bonkpanelchatinput").focus()
  1159. }
  1160. }
  1161. }
  1162. const title = document.createElement("div")
  1163. title.style.paddingBottom = "8px"
  1164. title.className = "commandscardtitle"
  1165. title.textContent = e
  1166. card.appendChild(title)
  1167. commandListContainer.appendChild(card)
  1168. })
  1169. },
  1170. nothing: () => {
  1171. SEARCH.remove()
  1172. }
  1173. }
  1174. let COMMANDLIST = [
  1175. {
  1176. name: "kick",
  1177. des: "Removes a player from the game",
  1178. param: ["player:ID"],
  1179. func: ["players"],
  1180. withoutMe: true,
  1181. host: true,
  1182. noQuick: true
  1183. },
  1184. {
  1185. name: "ban",
  1186. des: "Removes and prevents a player from joining the game",
  1187. param: ["player:ID"],
  1188. func: ["players"],
  1189. withoutMe: true,
  1190. host: true,
  1191. noQuick: true
  1192. },
  1193. {
  1194. name: "mute",
  1195. des: "Prevents the chat messages of a player from registering on your screen",
  1196. param: ["player:ID"],
  1197. func: ["players"],
  1198. withoutMe: true,
  1199. host: false
  1200. },
  1201. {
  1202. name: "unmute",
  1203. des: "Allows for future chat messages of a player to register on your screen again",
  1204. param: ["player:ID"],
  1205. func: ["players"],
  1206. withoutMe: true,
  1207. host: false
  1208. },
  1209. {
  1210. name: "balance",
  1211. des: "Changes the size of a player",
  1212. param: ["player:ID", "size:number"],
  1213. func: ["players", "nothing"],
  1214. host: true,
  1215. noQuick: true
  1216. },
  1217. {
  1218. name: "balanceall",
  1219. des: "Change the size of all players",
  1220. param: ["size:number"],
  1221. func: ["nothing"],
  1222. host: true,
  1223. noQuick: true
  1224. },
  1225. {
  1226. name: "roomname",
  1227. des: "Changes the name of the room",
  1228. param: ["name:string"],
  1229. func: ["nothing"],
  1230. host: true,
  1231. noQuick: true
  1232. },
  1233. {
  1234. name: "roompass",
  1235. des: "Changes the password of the room",
  1236. param: ["name:string"],
  1237. func: ["nothing"],
  1238. host: true,
  1239. noQuick: true
  1240. },
  1241. {
  1242. name: "clearroompass",
  1243. des: "The room no longer need a password to join",
  1244. param: [],
  1245. func: [],
  1246. host: true,
  1247. noQuick: true
  1248. },
  1249. {
  1250. name: "move",
  1251. des: "Move a player to another team",
  1252. param: ["player:ID", "team:ID"],
  1253. func: ["players", "teams"],
  1254. checkHost: true,
  1255. host: false,
  1256. noQuick: true
  1257. },
  1258. {
  1259. name: "moveall",
  1260. des: "Move all players to a team",
  1261. param: ["team:ID"],
  1262. func: ["teams"],
  1263. host: true,
  1264. noQuick: true
  1265. },
  1266. {
  1267. name: "mode",
  1268. des: "Changes the game mode of the room",
  1269. param: ["mode:ID"],
  1270. func: ["modes"],
  1271. host: true,
  1272. noQuick: true
  1273. },
  1274. {
  1275. name: "team",
  1276. des: "Enable or disable teams",
  1277. param: ["teams:option"],
  1278. func: ["option"],
  1279. option: ["on", "off"],
  1280. host: true,
  1281. noQuick: true
  1282. },
  1283. {
  1284. name: "lock",
  1285. des: "Allow or prevent players from moving themselves",
  1286. param: ["lock:option"],
  1287. func: ["option"],
  1288. option: ["on", "off"],
  1289. host: true,
  1290. noQuick: true
  1291. },
  1292. {
  1293. name: "link",
  1294. des: "Copy the auto join link to your clipboard",
  1295. param: [],
  1296. func: [],
  1297. host: false,
  1298. noQuick: true
  1299. },
  1300. {
  1301. name: "skin",
  1302. des: "Download the skin of a player",
  1303. param: ["player:ID"],
  1304. func: ["players"],
  1305. host: false
  1306. },
  1307. {
  1308. name: "start",
  1309. des: "Instantly start the game without countdown",
  1310. param: [],
  1311. func: [],
  1312. host: true,
  1313. noQuick: true
  1314. },
  1315. {
  1316. name: "round",
  1317. des: "Set the rounds to win",
  1318. param: ["rounds:number"],
  1319. func: ["nothing"],
  1320. host: true,
  1321. noQuick: true
  1322. },
  1323. {
  1324. name: "clear",
  1325. des: "Clears the chat",
  1326. param: [],
  1327. func: [],
  1328. host: false
  1329. },
  1330. {
  1331. name: "clearsys",
  1332. des: "Clears the system chat",
  1333. param: [],
  1334. func: [],
  1335. host: false
  1336. },
  1337. {
  1338. name: "size",
  1339. des: ["Set the size of the panels"],
  1340. param: ["panel:option", "topsize:number", "bottomsize:number"],
  1341. func: ["option", "nothing", "nothing"],
  1342. option: ["left", "right"],
  1343. host: false
  1344. },
  1345. {
  1346. name: "fav",
  1347. des: ["Adds the current map to your favourites list"],
  1348. param: [],
  1349. func: [],
  1350. host: false
  1351. },
  1352. {
  1353. name: "unfav",
  1354. des: ["Removes the current map from your favourites list"],
  1355. param: [],
  1356. func: [],
  1357. host: false
  1358. },
  1359. {
  1360. name: "givehost",
  1361. des: ["Gives host to a player"],
  1362. param: ["player:id"],
  1363. func: ["players"],
  1364. withoutMe: true,
  1365. host: true,
  1366. noQuick: true
  1367. },
  1368. {
  1369. name: "countdown",
  1370. des: ["Sends a countdown message"],
  1371. param: ["countdown:option"],
  1372. func: ["option"],
  1373. option: ["1", "2", "3"],
  1374. host: true,
  1375. noQuick: true
  1376. },
  1377. {
  1378. name: "abort",
  1379. des: ["Sends an abort countdown message"],
  1380. param: [],
  1381. func: [],
  1382. host: true,
  1383. noQuick: true
  1384. },
  1385. {
  1386. name: "xp",
  1387. des: ["Tells you how much xp you earned in this room"],
  1388. param: [],
  1389. func: [],
  1390. host: false
  1391. },
  1392. {
  1393. name: "earnxp",
  1394. des: ["Instantly gain xp"],
  1395. param: [],
  1396. func: [],
  1397. host: false
  1398. },
  1399. {
  1400. name: "ready",
  1401. des: ["Change your ready state"],
  1402. param: ["state:option"],
  1403. func: ["option"],
  1404. option: ["true", "false"],
  1405. host: false
  1406. },
  1407. {
  1408. name: "zoom",
  1409. des: "Set the scale of the stage",
  1410. param: ["scale:number"],
  1411. func: ["nothing"],
  1412. host: false
  1413. }
  1414. ]
  1415.  
  1416. // SCENE
  1417. let ROOM_VAR = {
  1418. xpEarned: 0,
  1419. myID: 0,
  1420. hostID: 0,
  1421. autoJoinID: null,
  1422. autoJoinPassBypass: null,
  1423. players: [],
  1424. quick: false,
  1425. bal: [],
  1426. tmpImgTextPing: [],
  1427. state: null,
  1428. stateFunction: null,
  1429. chatAvatarCache: [],
  1430. commandAvatarCache: [],
  1431. playersAvatarCache: []
  1432. }
  1433. let FUNCTIONS = {
  1434. showCommandHelper: (value = "") => {
  1435. if (value == "" || !value.startsWith("/") || value.startsWith("/ ")) {
  1436. commandContainer.style.display = "none"
  1437. return
  1438. }
  1439. const stage = value.split(" ")
  1440. if (stage.length == 1) {
  1441. commandContainer.style.display = "flex"
  1442. commandTopBar.textContent = stage[0].substring(1) || "Command Helper"
  1443. SEARCH.commands(stage[0].substring(1))
  1444. } else {
  1445. let index = COMMANDLIST.findIndex((z) => z.name === stage[0].substring(1))
  1446. if (index == -1) {
  1447. commandContainer.style.display = "none"
  1448. } else {
  1449. commandContainer.style.display = "flex"
  1450. let command = COMMANDLIST[index]
  1451. let params = ""
  1452. for (let i = 0; i < stage.length - 1; i++) {
  1453. if (command.param[i]) {
  1454. params += ` <${command.param[i]}>`
  1455. }
  1456. }
  1457. if (params == "") {
  1458. SEARCH["nothing"]()
  1459. } else if (command.func[stage.length - 2]) {
  1460. SEARCH[command.func[stage.length - 2]](command)
  1461. } else {
  1462. SEARCH["nothing"]()
  1463. }
  1464. commandTopBar.textContent = command.name + params
  1465. }
  1466. }
  1467. },
  1468. processCommand: (value = "") => {
  1469. if (value == "/" || value.startsWith("/ ")) {
  1470. FUNCTIONS.showSystemMessage("Failed, invalid command", "#b53030")
  1471. commandContainer.style.display = "none"
  1472. return
  1473. }
  1474. const stage = value.substring(1).split(" ")
  1475. if (COMMANDS[stage[0]] == null) {
  1476. FUNCTIONS.showSystemMessage("Failed, invalid command", "#b53030")
  1477. commandContainer.style.display = "none"
  1478. return
  1479. }
  1480. if (stage.length == 1) {
  1481. COMMANDS[stage[0]]()
  1482. } else {
  1483. let index = COMMANDLIST.findIndex((z) => z.name === stage[0])
  1484. if (index == -1) {
  1485. FUNCTIONS.showSystemMessage("Failed, invalid command", "#b53030")
  1486. } else {
  1487. let command = COMMANDLIST[index]
  1488. if (command.param.length == 0) {
  1489. COMMANDS[stage[0]]()
  1490. } else {
  1491. function splitWithTail(str, delim, count) {
  1492. var parts = str.split(delim)
  1493. var tail = parts.slice(count).join(delim)
  1494. var result = parts.slice(0, count)
  1495. result.push(tail)
  1496. return result
  1497. }
  1498. let val = splitWithTail(value, " ", command.param.length)
  1499. val.shift()
  1500. COMMANDS[stage[0]](...val)
  1501. }
  1502. }
  1503. }
  1504. commandContainer.style.display = "none"
  1505. },
  1506. createAvatarImage: (
  1507. avatar,
  1508. team_number,
  1509. appendlocation,
  1510. classList,
  1511. image_width,
  1512. image_height,
  1513. cache_storage,
  1514. cache_id,
  1515. cache_team,
  1516. shadow_thickness,
  1517. opacity
  1518. ) => {
  1519. const hexToHSL = (hex) => {
  1520. // Convert hex string to RGB values
  1521. let r = parseInt(hex.slice(1, 3), 16)
  1522. let g = parseInt(hex.slice(3, 5), 16)
  1523. let b = parseInt(hex.slice(5, 7), 16)
  1524.  
  1525. // Normalize RGB values
  1526. r /= 255
  1527. g /= 255
  1528. b /= 255
  1529.  
  1530. // Find the minimum and maximum RGB values
  1531. let min = Math.min(r, g, b)
  1532. let max = Math.max(r, g, b)
  1533. let diff = max - min
  1534.  
  1535. // Initialize HSL values
  1536. let h, s, l
  1537.  
  1538. // Calculate hue
  1539. if (diff === 0) {
  1540. h = 0
  1541. } else if (max === r) {
  1542. h = ((g - b) / diff) % 6
  1543. } else if (max === g) {
  1544. h = (b - r) / diff + 2
  1545. } else {
  1546. h = (r - g) / diff + 4
  1547. }
  1548. h = Math.round(60 * h)
  1549. if (h < 0) {
  1550. h += 360
  1551. }
  1552.  
  1553. // Calculate lightness
  1554. l = (min + max) / 2
  1555.  
  1556. // Calculate saturation
  1557. s = diff === 0 ? 0 : diff / (1 - Math.abs(2 * l - 1))
  1558. s = +(s * 100).toFixed(1)
  1559. l = +(l * 100).toFixed(1)
  1560.  
  1561. // Return HSL values as an object
  1562. return { h, s, l }
  1563. }
  1564. const HSLtoHex = (hue, saturation, lightness) => {
  1565. saturation /= 100
  1566. lightness /= 100
  1567. let s = (1 - Math.abs(2 * lightness - 1)) * saturation,
  1568. h = s * (1 - Math["abs"](((hue / 60) % 2) - 1)),
  1569. l = lightness - s / 2,
  1570. red = 0,
  1571. green = 0,
  1572. blue = 0
  1573. if (0 <= hue && hue < 60) {
  1574. red = s
  1575. green = h
  1576. blue = 0
  1577. } else if (60 <= hue && hue < 120) {
  1578. red = h
  1579. green = s
  1580. blue = 0
  1581. } else if (120 <= hue && hue < 180) {
  1582. red = 0
  1583. green = s
  1584. blue = h
  1585. } else if (180 <= hue && hue < 240) {
  1586. red = 0
  1587. green = h
  1588. blue = s
  1589. } else if (240 <= hue && hue < 300) {
  1590. red = h
  1591. green = 0
  1592. blue = s
  1593. } else if (300 <= hue && hue < 360) {
  1594. red = s
  1595. green = 0
  1596. blue = h
  1597. }
  1598. red = Math.round((red + l) * 255)
  1599. green = Math.round((green + l) * 255)
  1600. blue = Math.round((blue + l) * 255)
  1601. const rgbToHex = (r, g, b) =>
  1602. "#" +
  1603. [r, g, b]
  1604. .map((x) => {
  1605. const hex = x.toString(16)
  1606. return hex.length === 1 ? "0" + hex : hex
  1607. })
  1608. .join("")
  1609. return rgbToHex(red, green, blue)
  1610. }
  1611. const hueify = (hexcolour, hue_value) => {
  1612. let hsl = hexToHSL("#" + hexcolour.toString(16)["padStart"](6, "0"))
  1613. hsl.h = hue_value
  1614. return HSLtoHex(hsl.h, hsl.s, hsl.l)
  1615. }
  1616. const teamify = (colour) => {
  1617. if (team_number == 2) {
  1618. return hueify(colour, 4)
  1619. } else if (team_number == 3) {
  1620. return hueify(colour, 207)
  1621. } else if (team_number == 4) {
  1622. return hueify(colour, 122)
  1623. } else if (team_number == 5) {
  1624. return hueify(colour, 54)
  1625. }
  1626. return "#" + colour.toString(16)["padStart"](6, "0")
  1627. }
  1628. let svgcode = `
  1629. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="36" height="36">
  1630. <clipPath id="clipCircle"><circle cx="18" cy="18" r="15"/></clipPath>`
  1631. if (shadow_thickness > 0) {
  1632. svgcode += `<circle fill="#000000" fill-opacity="${opacity}" cx="${18 + shadow_thickness}" cy="${18 + shadow_thickness}" r="15"/>`
  1633. }
  1634. svgcode += `
  1635. <circle fill="${teamify(avatar.bc)}" cx="18" cy="18" r="15"/>
  1636. <g id="base" clip-path="url(#clipCircle)">`
  1637. avatar.layers
  1638. .slice()
  1639. .reverse()
  1640. .forEach((layer) => {
  1641. svgcode += window.bonkpanel_skins[layer.id - 1]
  1642. .match(/<g.+<\/g>/gs)[0]
  1643. .replace(/fill=".+?"/, `fill="${teamify(layer.color)}"`)
  1644. .replace(
  1645. /transform=".+?"/,
  1646. `
  1647. transform="matrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
  1648. translate(${layer.x + 18}, ${layer.y + 18})
  1649. rotate(${layer.angle})
  1650. scale(${layer.scale})
  1651. scale(${layer.flipX ? -1 : 1}, ${layer.flipY ? -1 : 1})"
  1652. `
  1653. )
  1654. })
  1655. svgcode += "</g>"
  1656. if (team_number >= 2 && team_number <= 5) {
  1657. svgcode += `<circle clip-path="url(#clipCircle)" fill="none" cx="18" cy="18" r="15" stroke-width="1.8" stroke="#`
  1658. if (team_number == 2) {
  1659. svgcode += `f44336"/>`
  1660. } else if (team_number == 3) {
  1661. svgcode += `2196f3"/>`
  1662. } else if (team_number == 4) {
  1663. svgcode += `4caf50"/>`
  1664. } else if (team_number == 5) {
  1665. svgcode += `ffeb3b"/>`
  1666. }
  1667. }
  1668. svgcode += "</svg>"
  1669. const image = document.createElement("img")
  1670. image.src = `data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(svgcode)))}`
  1671. image.style.width = image_width + "px"
  1672. image.style.height = image_height + "px"
  1673. if (document.body.contains(appendlocation)) {
  1674. while (appendlocation.firstChild) {
  1675. appendlocation.removeChild(appendlocation.firstChild)
  1676. }
  1677. appendlocation.appendChild(image)
  1678. if (classList != "") {
  1679. image.classList.add(classList)
  1680. }
  1681. }
  1682. if (cache_storage) {
  1683. if (!cache_storage[cache_id]) {
  1684. cache_storage[cache_id] = []
  1685. }
  1686. cache_storage[cache_id][cache_team] = image
  1687. }
  1688. return image
  1689. },
  1690. urlify: (text) => {
  1691. let urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/g
  1692. return text.replace(urlRegex, function (url, b, c) {
  1693. let url2 = c == "www." ? "https://" + url : url
  1694. return '<a href="' + url2 + '" target="_blank">' + url + "</a>"
  1695. })
  1696. },
  1697. showSystemMessage: (message, colour, inChat = false) => {
  1698. const systemcontainer = inChat ? document.getElementById("messagecontainer") : document.getElementById("systemcontainer")
  1699. if (systemcontainer == null) return
  1700.  
  1701. const needToScroll = systemcontainer.scrollTop + systemcontainer.clientHeight >= systemcontainer.scrollHeight - 5
  1702. const msgcontainer = document.createElement("div")
  1703. const msg = document.createElement("span")
  1704. msg.style.color = colour
  1705. msg.classList.add("newbonklobby_chat_status")
  1706. msg.appendChild(document.createTextNode("* " + message))
  1707. msgcontainer.appendChild(msg)
  1708. systemcontainer.appendChild(msgcontainer)
  1709. if (systemcontainer.childElementCount > 250) {
  1710. systemcontainer.removeChild(systemcontainer.firstChild)
  1711. }
  1712. if (needToScroll) {
  1713. systemcontainer.scrollTop = systemcontainer.scrollHeight
  1714. }
  1715. },
  1716. showChatMessage: (message, ID) => {
  1717. const messagecontainer = document.getElementById("messagecontainer")
  1718. if (messagecontainer == null) return
  1719.  
  1720. const messager = ROOM_VAR.players[ID]
  1721. if (messager == null) return
  1722. if (messager.mute) return
  1723.  
  1724. const needToScroll = messagecontainer.scrollTop + messagecontainer.clientHeight >= messagecontainer.scrollHeight - 5
  1725. const messageholder = document.createElement("div")
  1726. messagecontainer.appendChild(messageholder)
  1727.  
  1728. const colourbox = document.createElement("div")
  1729. colourbox.classList.add("newbonklobby_chat_msg_colorbox")
  1730. messageholder.appendChild(colourbox)
  1731.  
  1732. if (ROOM_VAR.chatAvatarCache[messager.userName] && ROOM_VAR.chatAvatarCache[messager.userName][1]) {
  1733. colourbox.appendChild(ROOM_VAR.chatAvatarCache[messager.userName][1].cloneNode(true))
  1734. } else {
  1735. try {
  1736. FUNCTIONS.createAvatarImage(messager.avatar, 1, colourbox, "newbonklobby_chat_msg_avatar", 12, 12, ROOM_VAR.chatAvatarCache, ID, 1, 2, 0.1)
  1737. } catch (error) {
  1738. console.error(error)
  1739. }
  1740. }
  1741.  
  1742. const name = document.createElement("span")
  1743. name.classList.add("newbonklobby_chat_msg_name")
  1744. name.innerText = `${messager.userName}: `
  1745. messageholder.append(name)
  1746.  
  1747. const msg = document.createElement("span")
  1748. msg.classList.add("newbonklobby_chat_msg_txt")
  1749. msg.innerHTML = FUNCTIONS.urlify(message)
  1750. messageholder.appendChild(msg)
  1751.  
  1752. if (needToScroll.childElementCount > 300) {
  1753. needToScroll.removeChild(needToScroll.firstChild)
  1754. }
  1755. if (needToScroll) {
  1756. messagecontainer.scrollTop = messagecontainer.scrollHeight
  1757. }
  1758. }
  1759. }
  1760. let SCENES = {
  1761. system: (panelID = "panel1") => {
  1762. document.getElementById(panelID).innerHTML = ""
  1763.  
  1764. const container = document.createElement("div")
  1765. container.id = "systemcontainer"
  1766. container.className = "chatcontainer"
  1767. document.getElementById(panelID).appendChild(container)
  1768. },
  1769. chat: (panelID = "panel3") => {
  1770. document.getElementById(panelID).innerHTML = ""
  1771.  
  1772. const container = document.createElement("div")
  1773. container.id = "messagecontainer"
  1774. container.className = "chatcontainer"
  1775. container.style.height = "calc(100% - 26px)"
  1776. document.getElementById(panelID).appendChild(container)
  1777.  
  1778. const lowerline = document.createElement("div")
  1779. lowerline.id = "bonkpanellowerline"
  1780. document.getElementById(panelID).appendChild(lowerline)
  1781.  
  1782. const lowerinstruction = document.createElement("div")
  1783. lowerinstruction.id = "bonkpanellowerinstruction"
  1784. lowerinstruction.innerText = "Press enter to send a message"
  1785. lowerinstruction.style.display = "block"
  1786. document.getElementById(panelID).appendChild(lowerinstruction)
  1787.  
  1788. const input = document.createElement("input")
  1789. input.id = "bonkpanelchatinput"
  1790. input.type = "text"
  1791. input.setAttribute("autocomplete", "off")
  1792. input.setAttribute("aria-autocomplete", "none")
  1793. input.style.pointerEvents = "none"
  1794. input.addEventListener("input", (e) => {
  1795. input.onkeydown = null
  1796. FUNCTIONS.showCommandHelper(e.target.value)
  1797. })
  1798. document.getElementById(panelID).appendChild(input)
  1799. },
  1800. leaderboard: (panelID = "panel2") => {
  1801. document.getElementById(panelID).innerHTML = ""
  1802. const container = document.createElement("div")
  1803. container.style = "width: 100%; height: 100%; display: flex; flex-direction: column; scroll-y: auto; font-family: futurept_b1;"
  1804.  
  1805. if (inLobby || ROOM_VAR.state == null || ROOM_VAR.state[4]?.wl == null) return
  1806. const div = document.createElement("div")
  1807. div.style = "font-size: 17px; padding: 5px 5px 0px; overflow: hidden;"
  1808. div.textContent = "Rounds to win: " + ROOM_VAR.state[4]?.wl
  1809. container.appendChild(div)
  1810.  
  1811. if (ROOM_VAR.state[0].scores.length <= 0) return
  1812. let leaderboardData = []
  1813. for (let i = 0; i < ROOM_VAR.state[0].scores.length; i++) {
  1814. const score = ROOM_VAR.state[0].scores[i]
  1815. if (score == null) continue
  1816. let scoreOwner = ""
  1817. if (ROOM_VAR.state[4].tea) {
  1818. switch (i) {
  1819. case 2:
  1820. scoreOwner = "Red Team"
  1821. break
  1822. case 3:
  1823. scoreOwner = "Blue Team"
  1824. break
  1825. case 4:
  1826. scoreOwner = "Green Team"
  1827. break
  1828. case 5:
  1829. scoreOwner = "Yellow Team"
  1830. break
  1831. }
  1832. } else if (ROOM_VAR.players[i]?.userName) {
  1833. scoreOwner = ROOM_VAR.players[i].userName
  1834. }
  1835. if (scoreOwner.length == 0) continue
  1836. leaderboardData.push({
  1837. owner: scoreOwner,
  1838. score: score
  1839. })
  1840. }
  1841. leaderboardData.sort((a, b) => b.score - a.score)
  1842. leaderboardData.forEach((e) => {
  1843. const div = document.createElement("div")
  1844. div.style = "font-size: 17px; padding: 5px 5px 0px; overflow: hidden;"
  1845. div.textContent = e.owner + ": " + e.score
  1846. container.appendChild(div)
  1847. })
  1848.  
  1849. document.getElementById(panelID).appendChild(container)
  1850. },
  1851. players: (panelID = "panel4") => {
  1852. document.getElementById(panelID).innerHTML = ""
  1853.  
  1854. const container = document.createElement("div")
  1855. container.id = "playerscontainer"
  1856. container.style = "width: 100%; height: 100%; display: flex; flex-direction: column; scroll-y: auto;"
  1857.  
  1858. ROOM_VAR.tmpImgTextPing = []
  1859. for (let i = 0; i < ROOM_VAR.players.length; i++) {
  1860. const player = ROOM_VAR.players[i]
  1861. if (player == null) continue
  1862.  
  1863. const playerContainer = document.createElement("div")
  1864. playerContainer.className = "newbonklobby_playerentry"
  1865. playerContainer.style =
  1866. "border-left: 4px solid var(--bonk_theme_primary_background, #e2e2e2) !important; border-right: 4px solid var(--bonk_theme_primary_background, #e2e2e2) !important; border-top: 4px solid var(--bonk_theme_primary_background, #e2e2e2) !important; background-color: var(--bonk_theme_primary_background, #e2e2e2); cursor: auto;"
  1867.  
  1868. const avatar = document.createElement("div")
  1869. avatar.className = "newbonklobby_playerentry_avatar"
  1870. avatar.style = `opacity: ${player.team === 0 ? "0.5" : "1"};`
  1871. if (ROOM_VAR.playersAvatarCache?.[player.userName]?.[player.team]) {
  1872. avatar.innerHTML = ROOM_VAR.commandAvatarCache[player.userName][player.team]
  1873. } else {
  1874. try {
  1875. avatar.innerHTML = FUNCTIONS.createAvatarImage(
  1876. player.avatar,
  1877. player.team,
  1878. null,
  1879. "",
  1880. 36,
  1881. 36,
  1882. ROOM_VAR.playersAvatarCache,
  1883. i,
  1884. player.team,
  1885. 1.1,
  1886. 0.3
  1887. ).outerHTML
  1888. } catch (error) {
  1889. console.error(error)
  1890. }
  1891. }
  1892. playerContainer.appendChild(avatar)
  1893.  
  1894. const name = document.createElement("div")
  1895. name.className = "newbonklobby_playerentry_name"
  1896. name.textContent = player.userName
  1897. playerContainer.appendChild(name)
  1898.  
  1899. const level = document.createElement("div")
  1900. level.className = "newbonklobby_playerentry_level"
  1901. level.textContent = player.guest ? "Guest" : `Level ${player.level}`
  1902. playerContainer.appendChild(level)
  1903.  
  1904. const size = document.createElement("div")
  1905. let sizeclass = ""
  1906. let sizetext = ""
  1907. if (ROOM_VAR.bal[i] && ROOM_VAR.bal[i] != 0) {
  1908. if (ROOM_VAR.bal[i] > 0) {
  1909. sizeclass = " newbonklobby_playerentry_balance_buff"
  1910. sizetext = "+" + ROOM_VAR.bal[i] + "%"
  1911. } else {
  1912. sizeclass = " newbonklobby_playerentry_balance_nerf"
  1913. sizetext = ROOM_VAR.bal[i] + "%"
  1914. }
  1915. }
  1916. size.className = "newbonklobby_playerentry_balance" + sizeclass
  1917. size.textContent = sizetext
  1918. playerContainer.appendChild(size)
  1919.  
  1920. const pingImg = document.createElement("img")
  1921. pingImg.src = "graphics/ping_5.png"
  1922. pingImg.className = "newbonklobby_playerentry_ping"
  1923. playerContainer.appendChild(pingImg)
  1924.  
  1925. const pingText = document.createElement("div")
  1926. pingText.className = "newbonklobby_playerentry_pingtext"
  1927. playerContainer.appendChild(pingText)
  1928.  
  1929. const hostImg = document.createElement("img")
  1930. hostImg.src = "graphics/host_0.png"
  1931. hostImg.className = "newbonklobby_playerentry_host"
  1932. playerContainer.appendChild(hostImg)
  1933.  
  1934. ROOM_VAR.tmpImgTextPing[i] = {
  1935. img: pingImg,
  1936. text: pingText,
  1937. host: hostImg
  1938. }
  1939.  
  1940. if (player.ready) {
  1941. const ready = document.createElement("img")
  1942. ready.className = "newbonklobby_playerentry_ready"
  1943. ready.src = "graphics/readytick.png"
  1944. playerContainer.appendChild(ready)
  1945. }
  1946.  
  1947. container.appendChild(playerContainer)
  1948. }
  1949. SCENES.updatePlayersPing()
  1950.  
  1951. document.getElementById(panelID).appendChild(container)
  1952. },
  1953. updatePlayersPing: () => {
  1954. for (let i = 0; i < ROOM_VAR.players.length; i++) {
  1955. const player = ROOM_VAR.players[i]
  1956. const element = ROOM_VAR.tmpImgTextPing[i]
  1957. if (element == null || player == null) continue
  1958.  
  1959. let imgSrc = 1
  1960. if (player.ping <= 100) {
  1961. imgSrc = 5
  1962. }
  1963. if (player.ping > 100 && player.ping <= 200) {
  1964. imgSrc = 4
  1965. }
  1966. if (player.ping > 200 && player.ping <= 300) {
  1967. imgSrc = 3
  1968. }
  1969. if (player.ping > 300 && player.ping <= 400) {
  1970. imgSrc = 2
  1971. }
  1972. if (player.ping > 400) {
  1973. imgSrc = 1
  1974. }
  1975. if (player.tabbed) {
  1976. imgSrc = "tab"
  1977. }
  1978.  
  1979. if (element.lastSet != imgSrc) {
  1980. element.lastSet = imgSrc
  1981. element.img.src = "graphics/ping_" + imgSrc + ".png"
  1982. }
  1983. if (imgSrc == "tab") {
  1984. element.text.textContent = "Tab"
  1985. } else if (player.ping === undefined) {
  1986. element.text.textContent = "-ms"
  1987. } else {
  1988. element.text.textContent = player.ping + "ms"
  1989. }
  1990. if (ROOM_VAR.hostID == i) {
  1991. if (element.hostLastSet != imgSrc) {
  1992. element.hostLastSet = imgSrc
  1993. element.host.src = "graphics/host_" + imgSrc + ".png"
  1994. }
  1995. } else {
  1996. if (element.hostLastSet !== 0) {
  1997. element.hostLastSet = 0
  1998. element.host.src = "graphics/host_0.png"
  1999. }
  2000. }
  2001. }
  2002. }
  2003. }
  2004. let inLobby = true
  2005.  
  2006. // ADD STYLE
  2007. const style = document.createElement("style")
  2008. style.innerHTML += /*css*/ `
  2009. *:focus {
  2010. outline: none;
  2011. }
  2012. .newbonklobby_chat_msg_colorbox {
  2013. user-select: none;
  2014. }
  2015. #bonkiocontainer {
  2016. margin: 10px !important;
  2017. flex: 0 0 auto;
  2018. }
  2019. #bonkpanelcontainer {
  2020. width: 100%;
  2021. height: 100%;
  2022. display: flex;
  2023. align-items: center;
  2024. justify-content: space-between;
  2025. }
  2026. #newbonklobby_chat_input {
  2027. width: 0px !important;
  2028. height: 0px !important;
  2029. }
  2030. #ingamechatinputtext {
  2031. width: 0px !important;
  2032. height: 0px !important;
  2033. }
  2034. #skinColourPickerContainerButton {
  2035. display: flex;
  2036. justify-content: space-between;
  2037. }
  2038. #skinColourPickerContainerButton > div {
  2039. padding: 0 10;
  2040. width: inherit;
  2041. margin-top: 7px;
  2042. margin-bottom: 2px;
  2043. display: inline-block;
  2044. height: 25px;
  2045. line-height: 25px;
  2046. }
  2047. #imageOverlayContainer {
  2048. position: absolute;
  2049. margin: auto;
  2050. left: 0;
  2051. right: 0;
  2052. top: 55px;
  2053. width: 245px;
  2054. height: 245px;
  2055. cursor: grab;
  2056. pointer-events: none;
  2057. overflow: hidden;
  2058. }
  2059. #imageOverlay {
  2060. width: 100%;
  2061. aspect-ratio: 1;
  2062. position: absolute;
  2063. top: 0;
  2064. left: 0;
  2065. background-repeat: no-repeat;
  2066. background-size: 100%;
  2067. background-position: center;
  2068. background-image: none;
  2069. transform: scale(100%);
  2070. opacity: 50%;
  2071. }
  2072. .panelcontainer {
  2073. flex: 1;
  2074. height: 100%;
  2075. background-color: var(--bonk_theme_primary_background, #e2e2e2) !important;
  2076. color: var(--bonk_theme_primary_text, #000000) !important;
  2077. }
  2078. .gutter {
  2079. background-color: var(--bonk_theme_window_color, #009688) !important;
  2080. background-repeat: no-repeat;
  2081. background-position: 50%;
  2082. }
  2083. .gutter.gutter-vertical {
  2084. background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAFAQMAAABo7865AAAABlBMVEVHcEzMzMzyAv2sAAAAAXRSTlMAQObYZgAAABBJREFUeF5jOAMEEAIEEFwAn3kMwcB6I2AAAAAASUVORK5CYII=');
  2085. cursor: row-resize;
  2086. }
  2087. .panel {
  2088. position: relative;
  2089. }
  2090. #commandcontainer {
  2091. position: absolute;
  2092. width: 100%;
  2093. height: 100%;
  2094. top: 0;
  2095. display: flex;
  2096. align-items: center;
  2097. justify-content: center;
  2098. font-family: "futurept_b1";
  2099. }
  2100. #commandbackground {
  2101. width: 100%;
  2102. height: 100%;
  2103. background-color: black;
  2104. opacity: 0.6;
  2105. }
  2106. #commandpanel {
  2107. position: absolute;
  2108. background-color: var(--greyWindowBGColor);
  2109. width: 80%;
  2110. height: 70%;
  2111. border-radius: 7px;
  2112. }
  2113. #commandtoptext {
  2114. font-family: "futurept_b1";
  2115. color: #ffffff;
  2116. text-align: center;
  2117. font-size: 20px;
  2118. line-height: 32px;
  2119. padding: 0px;
  2120. margin: 0px;
  2121. }
  2122. #commandlistcontainer {
  2123. height: calc(100% - 36px) !important;
  2124. }
  2125. .commandscardcontainer {
  2126. background-color: #eeeeee;
  2127. color: #222222;
  2128. border-radius: 5px;
  2129. user-select: none;
  2130. margin: 10px;
  2131. display: flex;
  2132. flex-direction: column;
  2133. cursor: pointer;
  2134. }
  2135. .commandscardtitle {
  2136. display: block;
  2137. text-align: left;
  2138. font-size: 20px;
  2139. padding-left: 10px;
  2140. padding-top: 8px;
  2141. }
  2142. .commandscarddescription {
  2143. display: block;
  2144. text-align: left;
  2145. font-size: 15px;
  2146. padding-left: 10px;
  2147. padding-right: 10px;
  2148. line-height: 20px;
  2149. white-space: pre-wrap;
  2150. margin-bottom: 5px;
  2151. }
  2152. .commandplayerimgcontainer {
  2153. width: 100px;
  2154. height: 100px;
  2155. }
  2156. .chatcontainer {
  2157. width: 100%;
  2158. height: 100%;
  2159. box-sizing: border-box;
  2160. margin: auto;
  2161. overflow-y: scroll;
  2162. overflow-x: hidden;
  2163. word-break: break-word;
  2164. user-select: text;
  2165. padding: 4px;
  2166. }
  2167. .chatcontainer::-webkit-scrollbar {width: 0.6em;}
  2168. .chatcontainer::-webkit-scrollbar-thumb {background-color: var(--bonk_theme_scrollbar_thumb, #757575) !important;}
  2169. .chatcontainer::-webkit-scrollbar-track {background-color: var(--bonk_theme_scrollbar_background) !important;}
  2170. #bonkpanellowerline {
  2171. background-color: #a5acb0;
  2172. width: 97%;
  2173. height: 1px;
  2174. }
  2175. #bonkpanellowerinstruction {
  2176. width: 97%;
  2177. height: 24px;
  2178. margin: auto;
  2179. color: #656565;
  2180. font-size: 16px;
  2181. font-family: "futurept_b1";
  2182. pointer-events: none;
  2183. }
  2184. #bonkpanelchatinput {
  2185. width: 97%;
  2186. height: 24px;
  2187. margin: auto;
  2188. border: 0px solid;
  2189. background: none;
  2190. font-family: "futurept_b1";
  2191. font-size: 16px;
  2192. color: #171717;
  2193. pointer-events: none;
  2194. }
  2195. `
  2196. document.body.appendChild(style)
  2197.  
  2198. // MONKEY PATCH SHAKE TWEEN OBJECT
  2199. var canvasStage = null
  2200. const symbolshakeTweenObject = Symbol("shakeTweenObject")
  2201. Object.defineProperty(Object.prototype, "shakeTweenObject", {
  2202. get() {
  2203. return this[symbolshakeTweenObject]
  2204. },
  2205. set(value) {
  2206. canvasStage = this
  2207. const original = this.createGradientBackground
  2208. this.createGradientBackground = function () {
  2209. original.call(this, arguments)
  2210. RESCALESTAGE()
  2211. }
  2212. this[symbolshakeTweenObject] = value
  2213. },
  2214. configurable: true
  2215. })
  2216. var scaler = 1
  2217. function RESCALESTAGE() {
  2218. if (canvasStage == null || canvasStage.stage == null) return
  2219. canvasStage.stage.scale.x = scaler
  2220. canvasStage.stage.scale.y = scaler
  2221.  
  2222. var tmpWidth = 730 * canvasStage.scaleRatio
  2223. var tmpHeight = 500 * canvasStage.scaleRatio
  2224. canvasStage.stage.x = tmpWidth / 2 - (tmpWidth * scaler) / 2
  2225. canvasStage.stage.y = tmpHeight / 2 - (tmpHeight * scaler) / 2
  2226.  
  2227. var superWidth = (780 * canvasStage.scaleRatio) / scaler
  2228. var superHeight = (550 * canvasStage.scaleRatio) / scaler
  2229.  
  2230. canvasStage.bgGradient.beginFill(0x3b536b)
  2231. canvasStage.bgGradient.drawRect(0, 0, superWidth, superHeight)
  2232. canvasStage.bgGradient.x = -(superWidth - tmpWidth) / 2
  2233. canvasStage.bgGradient.y = -(superHeight - tmpHeight) / 2
  2234. }
  2235.  
  2236. // MONKEY PATCH AVATAR SHOW
  2237. let showFunction = () => {}
  2238. const symbolShow = Symbol("show")
  2239. Object.defineProperty(Object.prototype, "show", {
  2240. get() {
  2241. return this[symbolShow]
  2242. },
  2243. set(value) {
  2244. if (typeof value == "function") {
  2245. const original = value
  2246. value = function () {
  2247. if (arguments[0]?.bc) {
  2248. showFunction = original
  2249. }
  2250. return original.apply(this, arguments)
  2251. }
  2252. }
  2253.  
  2254. this[symbolShow] = value
  2255. },
  2256. configurable: true
  2257. })
  2258.  
  2259. // MONKEY PATCH showColorPicker
  2260. var showColorPicker = null
  2261. var showColorPickerArguments = []
  2262. const symbolshowColorPicker = Symbol("showColorPicker")
  2263. Object.defineProperty(Object.prototype, "showColorPicker", {
  2264. get() {
  2265. return this[symbolshowColorPicker]
  2266. },
  2267. set(value) {
  2268. if (typeof value == "function") {
  2269. const original = value
  2270. value = function () {
  2271. showColorPicker = original
  2272. showColorPickerArguments = arguments
  2273. return original.apply(this, arguments)
  2274. }
  2275. }
  2276. this[symbolshowColorPicker] = value
  2277. }
  2278. })
  2279.  
  2280. // MONKEY PATCH hostHandlePlayerJoined
  2281. const symbolhostHandlePlayerJoined = Symbol("hostHandlePlayerJoined")
  2282. Object.defineProperty(Object.prototype, "hostHandlePlayerJoined", {
  2283. get() {
  2284. return this[symbolStep]
  2285. },
  2286. set(value) {
  2287. ROOM_VAR.stateFunction = this
  2288. this[symbolStep] = value
  2289. },
  2290. configurable: true
  2291. })
  2292.  
  2293. // MONKEY PATCH STEP
  2294. const symbolStep = Symbol("step")
  2295. Object.defineProperty(Object.prototype, "step", {
  2296. get() {
  2297. return this[symbolStep]
  2298. },
  2299. set(value) {
  2300. if (typeof value == "function") {
  2301. const original = value
  2302. value = function () {
  2303. if (arguments[0]?.scores) {
  2304. if (ws) {
  2305. ROOM_VAR.state = arguments
  2306. }
  2307. }
  2308. return original.apply(this, arguments)
  2309. }
  2310. }
  2311. this[symbolStep] = value
  2312. },
  2313. configurable: true
  2314. })
  2315.  
  2316. // MONKEY PATCH APPEND CHILD
  2317. let originalAppendChild = Element.prototype.appendChild
  2318. Element.prototype.appendChild = function () {
  2319. if (this == document.getElementById("newbonklobby_chat_content") || this == document.getElementById("ingamechatcontent")) {
  2320. if (
  2321. (arguments[0].firstChild?.className == "newbonklobby_chat_status" && inLobby) ||
  2322. (arguments[0].firstChild?.className == "ingamechatstatus" && !inLobby)
  2323. ) {
  2324. let text = arguments[0].textContent
  2325. if (text.startsWith("* Map added to favourites")) {
  2326. FUNCTIONS.showSystemMessage("Map added to favourites", "#b53030")
  2327. } else if (text.startsWith("* Couldn't favourite map because it isn't public")) {
  2328. FUNCTIONS.showSystemMessage("Failed, couldn't favourite map because it isn't public", "#b53030")
  2329. } else if (text.startsWith("* This map is already in your favourites!")) {
  2330. FUNCTIONS.showSystemMessage("This map is already in your favourites", "#b53030")
  2331. } else if (text.startsWith("* Couldn't favourite, something went wrong")) {
  2332. FUNCTIONS.showSystemMessage("Failed, something went wrong", "#b53030")
  2333. } else if (text.startsWith("* You must be logged in and the map must be a Bonk 2 map")) {
  2334. FUNCTIONS.showSystemMessage("Failed, you must be logged in and the map must be a Bonk 2 map", "#b53030")
  2335. } else if (text.startsWith("* Map removed from favourites")) {
  2336. FUNCTIONS.showSystemMessage("Map removed from favourites", "#b53030")
  2337. } else if (text.startsWith("* Couldn't unfavourite map because it isn't public")) {
  2338. FUNCTIONS.showSystemMessage("Failed, couldn't unfavourite map because it isn't public", "#b53030")
  2339. } else if (text.startsWith("* This map isn't in your favourites!")) {
  2340. FUNCTIONS.showSystemMessage("This map isn't in your favourites", "#b53030")
  2341. } else if (text.startsWith("* Couldn't unfavourite, something went wrong")) {
  2342. FUNCTIONS.showSystemMessage("Failed, something went wrong", "#b53030")
  2343. } else if (text.startsWith("* No replays in Football mode")) {
  2344. FUNCTIONS.showSystemMessage("Failed, no replays in football mode", "#b53030")
  2345. } else if (text.startsWith("* Please wait at least")) {
  2346. FUNCTIONS.showSystemMessage(text.substring(2).replace("Please", "Failed,"), "#b53030")
  2347. } else if (text.startsWith("* Recording failed")) {
  2348. FUNCTIONS.showSystemMessage("Failed, something went wrong", "#b53030")
  2349. } else if (text.startsWith("* Replay must be at least")) {
  2350. FUNCTIONS.showSystemMessage(text.substring(2).replace("Replay", "Failed, replay"), "#b53030")
  2351. } else if (text.startsWith("* The last")) {
  2352. FUNCTIONS.showSystemMessage(text.substring(2), "#b53030")
  2353. } else if (text.startsWith("* You and")) {
  2354. FUNCTIONS.showSystemMessage(text.substring(2), "#00675d")
  2355. } else if (text.endsWith("accepted your friend request ")) {
  2356. FUNCTIONS.showSystemMessage(text.substring(2), "#00675d")
  2357. } else if (text.startsWith("* Your clipboard has been set to:")) {
  2358. FUNCTIONS.showSystemMessage(`Link copied`, "#0955c7")
  2359. }
  2360. } else if (arguments[0].firstChild?.className == "newbonklobby_chat_status") {
  2361. let text = arguments[0].textContent
  2362. if (text.startsWith("* You and")) {
  2363. FUNCTIONS.showSystemMessage(text.substring(2), "#00675d")
  2364. } else if (text.endsWith("accepted your friend request ")) {
  2365. FUNCTIONS.showSystemMessage(text.substring(2), "#00675d")
  2366. } else if (text.startsWith("* Your clipboard has been set to:")) {
  2367. FUNCTIONS.showSystemMessage(`Link copied`, "#0955c7")
  2368. }
  2369. }
  2370. if (this == document.getElementById("newbonklobby_chat_content") && arguments[0].firstChild?.className == "newbonklobby_chat_msg_name") {
  2371. const systemcontainer = document.getElementById("systemcontainer")
  2372. if (systemcontainer) {
  2373. const needToScroll = systemcontainer.scrollTop + systemcontainer.clientHeight >= systemcontainer.scrollHeight - 5
  2374. systemcontainer.appendChild(arguments[0])
  2375. if (systemcontainer.childElementCount > 250) {
  2376. systemcontainer.removeChild(systemcontainer.firstChild)
  2377. }
  2378. if (needToScroll) {
  2379. systemcontainer.scrollTop = systemcontainer.scrollHeight
  2380. }
  2381. return
  2382. }
  2383. }
  2384. if (this == document.getElementById("newbonklobby_chat_content") && arguments[0].lastChild?.textContent == "[Accept]") {
  2385. const systemcontainer = document.getElementById("systemcontainer")
  2386. if (systemcontainer) {
  2387. const needToScroll = systemcontainer.scrollTop + systemcontainer.clientHeight >= systemcontainer.scrollHeight - 5
  2388. systemcontainer.appendChild(arguments[0])
  2389. if (systemcontainer.childElementCount > 250) {
  2390. systemcontainer.removeChild(systemcontainer.firstChild)
  2391. }
  2392. if (needToScroll) {
  2393. systemcontainer.scrollTop = systemcontainer.scrollHeight
  2394. }
  2395. return
  2396. }
  2397. }
  2398. } else if (
  2399. (arguments[0].textContent == "Unmute" || arguments[0].textContent == "Mute") &&
  2400. (arguments[0].className == "newbonklobby_playerentry_menu_button brownButton buttonShadow newbonklobby_playerentry_menu_button_warn" ||
  2401. arguments[0].className == "newbonklobby_playerentry_menu_button brownButton buttonShadow brownButton_classic")
  2402. ) {
  2403. arguments[0].addEventListener("click", () => {
  2404. const tmpelement = document.getElementsByClassName("newbonklobby_playerentry_menuhighlighted")[0]
  2405. if (tmpelement) {
  2406. const tmpname = tmpelement.getElementsByClassName("newbonklobby_playerentry_name")[0].textContent
  2407. for (let i = 0; i < ROOM_VAR.players.length; i++) {
  2408. if (ROOM_VAR.players[i].userName === tmpname) {
  2409. ROOM_VAR.players[i].mute = !ROOM_VAR.players[i].mute
  2410. break
  2411. }
  2412. }
  2413. }
  2414. })
  2415. } else if (this == document.body && arguments[0].tagName == "DIV") {
  2416. return
  2417. }
  2418.  
  2419. return originalAppendChild.apply(this, arguments)
  2420. }
  2421.  
  2422. // MONKEY PATCH ARRAY PUSH
  2423. let STARTGAME = null
  2424. let PROCESSCOMMAND = null
  2425. let originalArrayPush = Array.prototype.push
  2426. Array.prototype.push = function () {
  2427. if (arguments[0]?.eventName === "startGame") {
  2428. STARTGAME = arguments[0].callback
  2429. } else if (arguments[0]?.eventName === "processCommand") {
  2430. PROCESSCOMMAND = arguments[0].callback
  2431. }
  2432. originalArrayPush.apply(this, arguments)
  2433. }
  2434.  
  2435. // MONKEY PATCH EVENT LISTENER
  2436. let lockKeyboard = true
  2437. let _listeners = []
  2438. let originalAddEventListener = EventTarget.prototype.addEventListener
  2439. EventTarget.prototype.addEventListener = function (type, listener, useCapture) {
  2440. if (this == window && type == "keydown") {
  2441. let originalListener = listener
  2442. lockKeyboard = document.activeElement !== document.getElementById("bonkpanelchatinput")
  2443. listener = function () {
  2444. if (lockKeyboard) {
  2445. originalListener.apply(null, arguments)
  2446. }
  2447. }
  2448. }
  2449. _listeners.push({ type: type, listener: listener })
  2450. originalAddEventListener.apply(this, [type, listener, useCapture])
  2451. }
  2452. let originalRemoveEventListener = EventTarget.prototype.removeEventListener
  2453. EventTarget.prototype.removeEventListener = function (type, listener) {
  2454. if (this == window && type == "keydown") {
  2455. _listeners.forEach((e) => {
  2456. if (e.type == type) {
  2457. originalRemoveEventListener.apply(window, [type, e.listener])
  2458. }
  2459. })
  2460. _listeners = []
  2461. }
  2462. originalRemoveEventListener.apply(this, [type, listener])
  2463. }
  2464. let chatInputEvent = null
  2465. setTimeout(() => {
  2466. let originalOn = $.fn.on
  2467. $.fn.on = function (types, func) {
  2468. if (ws && types == "keydown") {
  2469. chatInputEvent = func
  2470. return false
  2471. } else {
  2472. return originalOn.apply(this, arguments)
  2473. }
  2474. }
  2475. }, 0)
  2476.  
  2477. // CUSTOM EVENT LISTENER
  2478. document.addEventListener("keydown", (e) => {
  2479. if (ws == null) return
  2480. if (e.code != "Enter") return
  2481. let chatinput = document.getElementById("bonkpanelchatinput")
  2482. let instruction = document.getElementById("bonkpanellowerinstruction")
  2483. if (inLobby) {
  2484. if (document.activeElement == document.getElementById("maploadwindowsearchinput")) {
  2485. document.getElementById("maploadwindowsearchbutton").click()
  2486. } else if (document.activeElement == chatinput) {
  2487. if (chatinput.value.startsWith("/")) {
  2488. FUNCTIONS.processCommand(chatinput.value)
  2489. } else if (chatinput.value != "") {
  2490. iosend([10, { message: chatinput.value }])
  2491. }
  2492. chatinput.value = ""
  2493. chatinput.blur()
  2494. instruction.style.display = "block"
  2495. chatinput.style.pointerEvents = "none"
  2496. } else {
  2497. chatinput.focus()
  2498. instruction.style.display = "none"
  2499. chatinput.style.pointerEvents = "auto"
  2500. }
  2501. } else {
  2502. if (document.activeElement == chatinput) {
  2503. if (chatinput.value.startsWith("/")) {
  2504. FUNCTIONS.processCommand(chatinput.value)
  2505. } else if (chatinput.value != "") {
  2506. iosend([10, { message: chatinput.value }])
  2507. }
  2508. chatinput.value = ""
  2509. chatinput.blur()
  2510. instruction.style.display = "block"
  2511. chatinput.style.pointerEvents = "none"
  2512. lockKeyboard = true
  2513. } else {
  2514. chatinput.focus()
  2515. instruction.style.display = "none"
  2516. chatinput.style.pointerEvents = "auto"
  2517. lockKeyboard = false
  2518. }
  2519. }
  2520. })
  2521. document.addEventListener("mouseup", (e) => {
  2522. if (ws && !inLobby) {
  2523. if (commandContainer.style.display != "none") {
  2524. lockKeyboard = false
  2525. } else if (typeof window.getSelection != "undefined" && window.getSelection().toString() != "") {
  2526. lockKeyboard = false
  2527. } else if (e.target.tagName == "INPUT") {
  2528. lockKeyboard = false
  2529. } else {
  2530. lockKeyboard = true
  2531. }
  2532. }
  2533. })
  2534. document.addEventListener("mousedown", (e) => {
  2535. if (ws && !inLobby) {
  2536. if (commandContainer.style.display != "none") {
  2537. lockKeyboard = false
  2538. } else if (e.target == document.getElementById("bonkpanelcontainer") || e.target == document.querySelector("#gamerenderer > canvas")) {
  2539. lockKeyboard = true
  2540. } else if (e.target.tagName == "INPUT") {
  2541. lockKeyboard = false
  2542. }
  2543. }
  2544. })
  2545.  
  2546. // ADD SKIN BUTTONS
  2547. const skinButtonsContainer = document.createElement("div")
  2548. skinButtonsContainer.style = "width: 100%; height: 30px; bottom: 15px; position: absolute; display: flex; justify-content: space-around;"
  2549. document.getElementById("skineditor_previewbox").appendChild(skinButtonsContainer)
  2550. const tmpEle = document.createElement("input")
  2551. tmpEle.type = "file"
  2552. tmpEle.style.display = "none"
  2553. tmpEle.addEventListener("change", () => {
  2554. let fr = new FileReader()
  2555. fr.onload = function () {
  2556. const result = JSON.parse(fr.result)
  2557. const tmpAvatar = new AVATAR()
  2558. tmpAvatar.bc = result.bc
  2559. tmpAvatar.layers = result.layers
  2560. showFunction(tmpAvatar)
  2561. }
  2562. fr.readAsText(tmpEle.files[0])
  2563. })
  2564. document.body.appendChild(tmpEle)
  2565.  
  2566. var overlayEditing = false
  2567. var pos1 = 0,
  2568. pos2 = 0,
  2569. pos3 = 0,
  2570. pos4 = 0,
  2571. overlayScale = 100,
  2572. overlayOpacity = 50
  2573. const tmpEle2 = document.createElement("input")
  2574. tmpEle2.type = "file"
  2575. tmpEle2.style.display = "none"
  2576. tmpEle2.addEventListener("change", () => {
  2577. let fr = new FileReader()
  2578. fr.onload = function () {
  2579. importImageOverlay.style.backgroundImage =
  2580. "url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iNDhweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iNDhweCIgZmlsbD0iI0ZGRkZGRiI+PHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIi8+PHBhdGggZD0iTTkgMTYuMTdMNC44MyAxMmwtMS40MiAxLjQxTDkgMTkgMjEgN2wtMS40MS0xLjQxTDkgMTYuMTd6Ii8+PC9zdmc+)"
  2581. imageOverlayContainer.style.pointerEvents = "auto"
  2582. imageOverlay.style.backgroundImage = `url(${fr.result})`
  2583. imageOverlay.style.top = "0px"
  2584. imageOverlay.style.left = "0px"
  2585. overlayScale = 100
  2586. overlayOpacity = 50
  2587. imageOverlay.style.transform = `scale(${overlayScale}%)`
  2588. imageOverlay.style.opacity = `${overlayOpacity}%`
  2589. imageOverlayContainer.onmousedown = function (event) {
  2590. pos3 = event.clientX
  2591. pos4 = event.clientY
  2592. window.onmousemove = function (e) {
  2593. pos1 = pos3 - e.clientX
  2594. pos2 = pos4 - e.clientY
  2595. pos3 = e.clientX
  2596. pos4 = e.clientY
  2597. imageOverlay.style.top = imageOverlay.offsetTop - pos2 + "px"
  2598. imageOverlay.style.left = imageOverlay.offsetLeft - pos1 + "px"
  2599. }
  2600. window.onmouseup = () => {
  2601. window.onmousemove = null
  2602. window.onmouseup = null
  2603. }
  2604. }
  2605. imageOverlayContainer.onwheel = function (event) {
  2606. if (event.shiftKey) {
  2607. if (event.deltaY < 0) {
  2608. overlayOpacity = Math.min(overlayOpacity + 1, 100)
  2609. } else {
  2610. overlayOpacity = Math.max(overlayOpacity - 1, 0)
  2611. }
  2612. imageOverlay.style.opacity = `${overlayOpacity}%`
  2613. } else {
  2614. if (event.deltaY < 0) {
  2615. overlayScale += 1
  2616. } else {
  2617. overlayScale -= 1
  2618. }
  2619. imageOverlay.style.transform = `scale(${overlayScale}%)`
  2620. }
  2621. }
  2622. document.getElementById("skineditor_previewbox_skincontainer").style.pointerEvents = "none"
  2623. overlayEditing = true
  2624. }
  2625. fr.readAsDataURL(tmpEle2.files[0])
  2626. })
  2627. const importSkin = document.createElement("div")
  2628. importSkin.className = "brownButton brownButton_classic"
  2629. importSkin.style.width = "30px"
  2630. importSkin.style.height = "30px"
  2631. importSkin.addEventListener("click", () => {
  2632. tmpEle.click()
  2633. })
  2634. importSkin.style.backgroundImage =
  2635. "url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyNy4zLjEsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiDQoJIHZpZXdCb3g9IjAgMCA0OCA0OCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgNDggNDg7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxzdHlsZSB0eXBlPSJ0ZXh0L2NzcyI+DQoJLnN0MHtmaWxsOiNGRkZGRkY7fQ0KPC9zdHlsZT4NCjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik0xMSw0MGMtMC44LDAtMS41LTAuMy0yLjEtMC45QzguMywzOC41LDgsMzcuOCw4LDM3di03LjFoM1YzN2gyNnYtNy4xaDNWMzdjMCwwLjgtMC4zLDEuNS0wLjksMi4xDQoJQzM4LjUsMzkuNywzNy44LDQwLDM3LDQwSDExeiBNMjIuNSwzMi4zVjEzLjhsLTYsNmwtMi4xLTIuMUwyNCw4bDkuNyw5LjZsLTIuMiwyLjFsLTYtNnYxOC41SDIyLjV6Ii8+DQo8L3N2Zz4NCg==)"
  2636. const importImageOverlay = document.createElement("div")
  2637. importImageOverlay.className = "brownButton brownButton_classic"
  2638. importImageOverlay.style.width = "30px"
  2639. importImageOverlay.style.height = "30px"
  2640. importImageOverlay.style.backgroundSize = "80%"
  2641. importImageOverlay.style.backgroundPosition = "center"
  2642. importImageOverlay.style.backgroundRepeat = "no-repeat"
  2643. importImageOverlay.style.backgroundImage =
  2644. "url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iNDhweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iNDhweCIgZmlsbD0iI0ZGRkZGRiI+PHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIi8+PHBhdGggZD0iTTIyIDE4VjJINnYxNmgxNnptLTExLTZsMi4wMyAyLjcxTDE2IDExbDQgNUg4bDMtNHpNMiA2djE2aDE2di0ySDRWNkgyeiIvPjwvc3ZnPg==)"
  2645. importImageOverlay.addEventListener("click", () => {
  2646. if (overlayEditing) {
  2647. importImageOverlay.style.backgroundImage =
  2648. "url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iNDhweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iNDhweCIgZmlsbD0iI0ZGRkZGRiI+PHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIi8+PHBhdGggZD0iTTIyIDE4VjJINnYxNmgxNnptLTExLTZsMi4wMyAyLjcxTDE2IDExbDQgNUg4bDMtNHpNMiA2djE2aDE2di0ySDRWNkgyeiIvPjwvc3ZnPg==)"
  2649. imageOverlayContainer.style.pointerEvents = null
  2650. document.getElementById("skineditor_previewbox_skincontainer").style.pointerEvents = null
  2651. overlayEditing = false
  2652. } else {
  2653. imageOverlay.style.backgroundImage = null
  2654. tmpEle2.click()
  2655. }
  2656. })
  2657. document.getElementById("skineditor_cancelbutton").style.position = "initial"
  2658. document.getElementById("skineditor_savebutton").style.position = "initial"
  2659. skinButtonsContainer.appendChild(document.getElementById("skineditor_cancelbutton"))
  2660. skinButtonsContainer.appendChild(document.getElementById("skineditor_savebutton"))
  2661. skinButtonsContainer.appendChild(importImageOverlay)
  2662. skinButtonsContainer.appendChild(importSkin)
  2663.  
  2664. const skinColourPickerContainerButton = document.createElement("div")
  2665. skinColourPickerContainerButton.id = "skinColourPickerContainerButton"
  2666. const skinHexColourPicker = document.createElement("div")
  2667. skinHexColourPicker.className = "brownButton brownButton_classic buttonShadow"
  2668. skinHexColourPicker.innerText = "#"
  2669. skinHexColourPicker.onclick = () => {
  2670. const hexCode = window.prompt("Hex Code", "#")
  2671. try {
  2672. showColorPickerArguments[0] = parseInt(hexCode.replace("#", ""), 16)
  2673. showColorPicker(...showColorPickerArguments)
  2674. } catch (error) {}
  2675. }
  2676. skinColourPickerContainerButton.appendChild(skinHexColourPicker)
  2677. skinColourPickerContainerButton.appendChild(document.getElementById("skineditor_colorpicker_cancelbutton"))
  2678. skinColourPickerContainerButton.appendChild(document.getElementById("skineditor_colorpicker_savebutton"))
  2679. document.getElementById("skineditor_colorpicker").appendChild(skinColourPickerContainerButton)
  2680.  
  2681. // SKIN IMAGE OVERLAY
  2682. const imageOverlayContainer = document.createElement("div")
  2683. imageOverlayContainer.id = "imageOverlayContainer"
  2684. const imageOverlay = document.createElement("div")
  2685. imageOverlay.id = "imageOverlay"
  2686. imageOverlayContainer.appendChild(imageOverlay)
  2687. document.getElementById("skineditor_previewbox").appendChild(imageOverlayContainer)
  2688.  
  2689. // WS SENDER AND RECEIVER
  2690. let wsextra = []
  2691. let ws = null
  2692. let originalSend = window.WebSocket.prototype.send
  2693. window.WebSocket.prototype.send = function (args) {
  2694. if (this.url.includes(".bonk.io/socket.io/?EIO=3&transport=websocket&sid=")) {
  2695. if (typeof args == "string" && !wsextra.includes(this)) {
  2696. if (!ws) {
  2697. ws = this
  2698. }
  2699. try {
  2700. if (args.startsWith("42[")) {
  2701. let data = JSON.parse(/42(.*)/.exec(args)[1])
  2702. handleOwnData(data, this)
  2703. }
  2704. } catch (error) {
  2705. console.log(args)
  2706. console.log(error)
  2707. }
  2708. }
  2709. } else if (args.includes("rport")) {
  2710. return
  2711. }
  2712. if (this.url.includes(".bonk.io/socket.io/?EIO=3&transport=websocket&sid=") && !this.injected) {
  2713. this.injected = true
  2714.  
  2715. let originaReceiveMessage = this.onmessage
  2716. this.onmessage = (e) => {
  2717. if (!wsextra.includes(this)) {
  2718. if (typeof e.data == "string") {
  2719. try {
  2720. if (e.data.startsWith("42[")) {
  2721. handleData(JSON.parse(/42(.*)/.exec(e.data)[1]), this)
  2722. }
  2723. } catch (error) {
  2724. console.log(e.data)
  2725. console.log(error)
  2726. }
  2727. }
  2728. }
  2729. return originaReceiveMessage.call(this, e)
  2730. }
  2731.  
  2732. let originalClose = this.onclose
  2733. this.onclose = function () {
  2734. if (wsextra.includes(this)) {
  2735. wsextra.splice(wsextra.indexOf(this), 1)
  2736. } else {
  2737. ws = null
  2738. panelLeft.style.visibility = "hidden"
  2739. panelRight.style.visibility = "hidden"
  2740. }
  2741. return originalClose.call(this)
  2742. }
  2743. }
  2744. return originalSend.call(this, args)
  2745. }
  2746. function iosend(data) {
  2747. if (ws == null) return
  2748. ws.send(`42${JSON.stringify(data)}`)
  2749. }
  2750. function ioreceive(data) {
  2751. if (ws == null) return
  2752. ws.onmessage({ data: `42${JSON.stringify(data)}` })
  2753. }
  2754.  
  2755. // HANDLE DATA
  2756. function handleData(data, websocket) {
  2757. switch (data[0]) {
  2758. case 1:
  2759. // got ping data
  2760. originalSend.call(websocket, `42[1,{"id":${data[1]}}]`)
  2761. for (const id in data[1]) {
  2762. if (ROOM_VAR.players[id]) {
  2763. ROOM_VAR.players[id].ping = data[1][id]
  2764. }
  2765. }
  2766. SCENES.updatePlayersPing()
  2767. break
  2768. case 2:
  2769. // room Created
  2770. inLobby = true
  2771. ROOM_VAR.quick = false
  2772. ROOM_VAR.bal = []
  2773. ROOM_VAR.chatAvatarCache = []
  2774. ROOM_VAR.commandAvatarCache = []
  2775. ROOM_VAR.playersAvatarCache = []
  2776. ROOM_VAR.xpEarned = 0
  2777. SCENES.system()
  2778. SCENES.chat()
  2779. SCENES.players()
  2780. SCENES.leaderboard()
  2781. break
  2782. case 3:
  2783. // joined Room
  2784. panelLeft.style.visibility = "visible"
  2785. panelRight.style.visibility = "visible"
  2786. ROOM_VAR.players = data[3]
  2787. ROOM_VAR.hostID = data[2]
  2788. ROOM_VAR.quick = false
  2789. ROOM_VAR.xpEarned = 0
  2790. ROOM_VAR.chatAvatarCache = []
  2791. ROOM_VAR.commandAvatarCache = []
  2792. ROOM_VAR.playersAvatarCache = []
  2793. SCENES.system()
  2794. SCENES.chat()
  2795. SCENES.players()
  2796. if (ROOM_VAR.players[data[1]].userName == document.getElementById("pretty_top_name").textContent) {
  2797. ROOM_VAR.myID = data[1]
  2798. ws = websocket
  2799. } else {
  2800. wsextra.push(websocket)
  2801. }
  2802. break
  2803. case 4:
  2804. // new player joined
  2805. FUNCTIONS.showSystemMessage(data[3] + " has joined the game", "#b53030", true)
  2806. ROOM_VAR.players[data[1]] = {
  2807. peerID: data[2],
  2808. userName: data[3],
  2809. guest: data[4],
  2810. level: data[5],
  2811. team: data[6],
  2812. avatar: data[7]
  2813. }
  2814. SCENES.players()
  2815. break
  2816. case 5:
  2817. // someone left
  2818. FUNCTIONS.showSystemMessage(ROOM_VAR.players[data[1]].userName + " has left the game", "#b53030", true)
  2819. ROOM_VAR.players[data[1]] = null
  2820. SCENES.players()
  2821. break
  2822. case 6:
  2823. // host left
  2824. ROOM_VAR.hostID = data[2]
  2825. if (data[2] == -1) {
  2826. FUNCTIONS.showSystemMessage(`${ROOM_VAR.players[data[1]].userName} has left the game and closed the room`, "#b53030", true)
  2827. } else {
  2828. FUNCTIONS.showSystemMessage(
  2829. `${ROOM_VAR.players[data[1]].userName} has left the game and ${ROOM_VAR.players[data[2]].userName} is now the game host`,
  2830. "#b53030",
  2831. true
  2832. )
  2833. }
  2834. if (data[2] == ROOM_VAR.myID) {
  2835. FUNCTIONS.showSystemMessage("You are now the host of this game", "#800d6e")
  2836. }
  2837. ROOM_VAR.players[data[1]] = null
  2838. SCENES.players()
  2839. break
  2840. case 8:
  2841. // ready change
  2842. ROOM_VAR.players[data[1]].ready = data[2]
  2843. SCENES.players()
  2844. break
  2845. case 13:
  2846. // return to lobby
  2847. inLobby = true
  2848. SCENES.leaderboard()
  2849. break
  2850. case 15:
  2851. // game started
  2852. inLobby = false
  2853. SCENES.leaderboard()
  2854. break
  2855. case 16:
  2856. // status (something like chat rate limited)
  2857. if (["rate_limit_ready", "chat_rate_limit"].includes(data[1])) {
  2858. FUNCTIONS.showSystemMessage("You're doing that too much!", "#cc4444")
  2859. } else if (data[1] == "teams_locked") {
  2860. FUNCTIONS.showSystemMessage("Failed, teams have been locked, only the host can assign teams", "#cc4444")
  2861. }
  2862. break
  2863. case 18:
  2864. // team changed
  2865. ROOM_VAR.players[data[1]].team = data[2]
  2866. SCENES.players()
  2867. break
  2868. case 19:
  2869. // team lock changed
  2870. if (data[1]) {
  2871. FUNCTIONS.showSystemMessage("Teams have been locked, only the host can assign teams", "#b53030")
  2872. } else {
  2873. FUNCTIONS.showSystemMessage("Teams have been unlocked", "#b53030")
  2874. }
  2875. break
  2876. case 20:
  2877. // chat messages
  2878. FUNCTIONS.showChatMessage(data[2], data[1])
  2879. break
  2880. case 21:
  2881. // game settings first load
  2882. inLobby = true
  2883. SCENES.leaderboard()
  2884. ROOM_VAR.bal = data[1].bal
  2885. break
  2886. case 24:
  2887. // kicked
  2888. FUNCTIONS.showSystemMessage(`${ROOM_VAR.players[data[1]].userName} was ${data[2] ? "kicked" : "banned"}!`, "#b53030")
  2889. break
  2890. case 26:
  2891. // change gamo
  2892. let mode = "Classic"
  2893. switch (data[2]) {
  2894. case "b":
  2895. mode = "Classic"
  2896. break
  2897. case "ar":
  2898. mode = "Arrows"
  2899. break
  2900. case "ard":
  2901. mode = "Death Arrows"
  2902. break
  2903. case "sp":
  2904. mode = "Grapple"
  2905. break
  2906. case "f":
  2907. mode = "Football"
  2908. break
  2909. case "v":
  2910. mode = "VTOL"
  2911. break
  2912. }
  2913. FUNCTIONS.showSystemMessage("Game mode changed to: " + mode, "#800d6e")
  2914. break
  2915. case 27:
  2916. // change win lose
  2917. FUNCTIONS.showSystemMessage("Rounds to win changed to: " + data[1], "#800d6e")
  2918. break
  2919. case 32:
  2920. // afk warn
  2921. FUNCTIONS.showSystemMessage("STOP AFK, WAKE UP!!!", "#b53030")
  2922. break
  2923. case 36:
  2924. // balance
  2925. ROOM_VAR.bal[data[1]] = data[2]
  2926. SCENES.players()
  2927. break
  2928. case 39:
  2929. // team settings change
  2930. let onoroff = data[1] ? "on" : "off"
  2931. FUNCTIONS.showSystemMessage(`Teams ${onoroff}`, "#800d6e")
  2932. break
  2933. case 40:
  2934. // arm record
  2935. if (data[1] != ROOM_VAR.myID) {
  2936. FUNCTIONS.showSystemMessage(`${ROOM_VAR.players[data[1]].userName} requests record gameplay`, "#b53030")
  2937. }
  2938. break
  2939. case 41:
  2940. // host changed
  2941. FUNCTIONS.showSystemMessage(
  2942. ROOM_VAR.players[data[1].oldHost].userName +
  2943. " has given host privileges to " +
  2944. ROOM_VAR.players[data[1].newHost].userName +
  2945. ", who is now the game host",
  2946. "#b53030"
  2947. )
  2948. if (data[1].newHost == ROOM_VAR.myID) {
  2949. FUNCTIONS.showSystemMessage("You are now the host of this game", "#800d6e")
  2950. }
  2951. ROOM_VAR.hostID = data[1].newHost
  2952. SCENES.players()
  2953. break
  2954. case 43:
  2955. // countdown
  2956. FUNCTIONS.showSystemMessage("Game starting in " + data[1], "#0955c7")
  2957. break
  2958. case 44:
  2959. // countdown aborted
  2960. FUNCTIONS.showSystemMessage("Countdown aborted!", "#0955c7")
  2961. break
  2962. case 45:
  2963. // player leveled up
  2964. ROOM_VAR.players[data[1].sid].level = data[1].lv
  2965. SCENES.players()
  2966. break
  2967. case 46:
  2968. // gained xp
  2969. ROOM_VAR.xpEarned += 100
  2970. break
  2971. case 48:
  2972. // show in game data if just joined
  2973. inLobby = false
  2974. SCENES.leaderboard()
  2975. ROOM_VAR.bal = data[1].gs.bal
  2976. ROOM_VAR.quick = data[1].gs.q
  2977. break
  2978. case 49:
  2979. // autojoin
  2980. ROOM_VAR.autoJoinID = data[1]
  2981. ROOM_VAR.autoJoinPassBypass = data[2]
  2982. break
  2983. case 52:
  2984. // tabbed update
  2985. ROOM_VAR.players[data[1]].tabbed = data[2]
  2986. SCENES.updatePlayersPing()
  2987. break
  2988. case 58:
  2989. // room name changed
  2990. FUNCTIONS.showSystemMessage("Room name changed to: " + data[1], "#800d6e")
  2991. break
  2992. case 59:
  2993. // room password changed
  2994. if (data[1]) {
  2995. FUNCTIONS.showSystemMessage("A new password has been set for this room", "#800d6e")
  2996. } else {
  2997. FUNCTIONS.showSystemMessage("This room no longer requires a password to join.", "#800d6e")
  2998. }
  2999. break
  3000. }
  3001. }
  3002.  
  3003. // HANDLE OWN DATA
  3004. function handleOwnData(data, websocket) {
  3005. switch (data[0]) {
  3006. case 5:
  3007. ROOM_VAR.quick = data[1].gs.q
  3008. break
  3009. case 14:
  3010. // Own quit game
  3011. inLobby = true
  3012. SCENES.leaderboard()
  3013. break
  3014. case 12:
  3015. // Created room
  3016. ROOM_VAR.myID = 0
  3017. ROOM_VAR.hostID = 0
  3018. ws = websocket
  3019. panelLeft.style.visibility = "visible"
  3020. panelRight.style.visibility = "visible"
  3021. ROOM_VAR.players = []
  3022. let tmpdata = data[1]
  3023. tmpdata.userName = document.getElementById("pretty_top_name").innerText
  3024. if (!data[1].guest) {
  3025. tmpdata.level = parseInt(document.getElementById("pretty_top_level").innerText.substring(3))
  3026. }
  3027. ROOM_VAR.players.push(tmpdata)
  3028. break
  3029. case 20:
  3030. // Change GAMO
  3031. ioreceive([26, data[1].ga, data[1].mo])
  3032. break
  3033. case 21:
  3034. // Change win lose
  3035. ioreceive([27, data[1].w])
  3036. break
  3037. case 32:
  3038. // Change teamchain
  3039. ioreceive([39, data[1].t])
  3040. break
  3041. case 29:
  3042. // Change balance
  3043. ioreceive([36, data[1].sid, data[1].bal])
  3044. break
  3045. }
  3046. }
  3047.  
  3048. setInterval(() => {
  3049. SCENES.leaderboard()
  3050. }, 1000)