Library For Mxobot

Library for Mxobot

当前为 2024-05-04 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/461063/1370924/Library%20For%20Mxobot.js

  1. // ==UserScript==
  2. // @name MXO LİBRARY
  3. // @namespace http://tampermonkey.net/<3nevin
  4. // @version 1.1
  5. // @description LİBRARY FOR MXOBOT
  6. // @author ngixl
  7. // @match https://pixelplace.io/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=pixelplace.io
  9. // @grant unsafeWindow
  10. // @require https://gf.qytechs.cn/scripts/462620-mxobot-example-bot/code/MxoBot%20Example%20Bot.js
  11.  
  12. /* globals unsafeWindow*/
  13. /*jshint esversion: 11 */
  14.  
  15. Object.defineProperty(unsafeWindow, "console", {
  16. value: console,
  17. writable: false,
  18. });
  19.  
  20. class MMXOLoggerFactory {
  21. static TEMPLATE = "%c[MMXOCore] %s: %s";
  22. static CSS_INFO = "color:green";
  23. static CSS_WARNING = "color:yellow;";
  24. static CSS_ERROR = "color:red;font-weight: bold;";
  25. static TEMPLATE_INFO = "INFO";
  26. static TEMPLATE_WARNING = "WARNING";
  27. static TEMPLATE_ERROR = "ERROR";
  28. static LEVEL_INFO = 0;
  29. static LEVEL_WARNING = 1;
  30. static LEVEL_ERROR = 2;
  31. LEVEL = MMXOLoggerFactory.LEVEL_INFO;
  32. constructor() {
  33. this.listeners = [];
  34. this.listeners.push(function (template, css, level, msg) {
  35. console.log(template, css, level, msg);
  36. });
  37. }
  38. dispatch(template, css, level, msg) {
  39. this.listeners.forEach((listener) => {
  40. listener(template, css, level, msg);
  41. });
  42. }
  43. info(msg) {
  44. if (this.LEVEL <= MMXOLoggerFactory.LEVEL_INFO) {
  45. this.dispatch(
  46. MMXOLoggerFactory.TEMPLATE,
  47. MMXOLoggerFactory.CSS_INFO,
  48. MMXOLoggerFactory.TEMPLATE_INFO,
  49. msg
  50. );
  51. }
  52. }
  53. warning(msg) {
  54. if (this.LEVEL <= MMXOLoggerFactory.LEVEL_WARNING) {
  55. this.dispatch(
  56. MMXOLoggerFactory.TEMPLATE,
  57. MMXOLoggerFactory.CSS_WARNING,
  58. MMXOLoggerFactory.TEMPLATE_WARNING,
  59. msg
  60. );
  61. }
  62. }
  63. error(msg) {
  64. if (this.LEVEL <= MMXOLoggerFactory.LEVEL_ERROR) {
  65. this.dispatch(
  66. MMXOLoggerFactory.TEMPLATE,
  67. MMXOLoggerFactory.CSS_ERROR,
  68. MMXOLoggerFactory.TEMPLATE_ERROR,
  69. msg
  70. );
  71. throw Error(msg);
  72. }
  73. }
  74. }
  75.  
  76. class MMXOImageConverter {
  77. static getClosestColor(r, g, b, palette) {
  78. let closestColor = {r: 0, g: 0, b: 0};
  79. let closestDistance = Number.MAX_VALUE;
  80. for (let i = 0;i < palette.colors.length; i++) {
  81. let bigint = palette.colors[i];
  82. let p_r = (bigint >> 16) & 255;
  83. let p_g = (bigint >> 8) & 255;
  84. let p_b = bigint & 255;
  85. let distance = (r - p_r)**2 + (g - p_g)**2 + (b - p_b)**2;
  86. if (distance < closestDistance) {
  87. closestColor = {r: p_r, g: p_g, b: p_b};
  88. closestDistance = distance;
  89. }
  90. }
  91. return closestColor;
  92. }
  93. static floydSteinberg(img_data, w, h, palette) {
  94. if (unsafeWindow.MXOBOT_DO_NOT_DITHER === true) {
  95. return img_data;
  96. }
  97. let dithered = new Uint8ClampedArray(img_data.data);
  98. let error_matrix = new Float32Array(w * h * 4);
  99. for (let y = 0; y < h; y++) {
  100. for (let x = 0;x < w; x++) {
  101. let i = (y * w + x) * 4;
  102. let r = img_data.data[i] + error_matrix[i];
  103. let g = img_data.data[i + 1] + error_matrix[i + 1];
  104. let b = img_data.data[i + 2] + error_matrix[i + 2];
  105. let closest = MMXOImageConverter.getClosestColor(r, g, b, palette);
  106. dithered[i] = closest.r;
  107. dithered[i + 1] = closest.g;
  108. dithered[i + 2] = closest.b;
  109. dithered[i + 3] = img_data.data[i + 3];
  110. let err_r = r - closest.r;
  111. let err_g = g - closest.g;
  112. let err_b = b - closest.b;
  113. if (x + 1 < w) {
  114. error_matrix[i + 4] += err_r * 7 / 16;
  115. error_matrix[i + 5] += err_g * 7 / 16;
  116. error_matrix[i + 6] += err_b * 7 / 16;
  117. }
  118. if (y + 1 < h) {
  119. if (x > 0) {
  120. error_matrix[i + 4 * w - 4] += err_r * 3 / 16;
  121. error_matrix[i + 4 * w - 3] += err_g * 3 / 16;
  122. error_matrix[i + 4 * w - 2] += err_b * 3 / 16;
  123. }
  124. error_matrix[i + 4 * w] += err_r * 5 / 16;
  125. error_matrix[i + 4 * w + 1] += err_g * 5 / 16;
  126. error_matrix[i + 4 * w + 2] += err_b * 5 / 16;
  127. if (x + 1 < w) {
  128. error_matrix[i + 4 * w + 4] += err_r * 1 / 16;
  129. error_matrix[i + 4 * w + 5] += err_g * 1 / 16;
  130. error_matrix[i + 4 * w + 6] += err_b * 1 / 16;
  131. }
  132. }
  133. }
  134. }
  135. const dithered_img_data = new ImageData(dithered, w, h);
  136. return dithered_img_data;
  137. }
  138. }
  139.  
  140. const MMXOLogger = new MMXOLoggerFactory();
  141.  
  142. class MMXOPalette {
  143. static PALETTE_LOAD_STATIC = 0;
  144. static PALETTE_LOAD_DYNAMIC = 1;
  145. static hexStrToHex(hex_str) {
  146. return parseInt(hex_str.slice(1), 16);
  147. }
  148. static STATIC_COLORS = [
  149. 16777215, 12895428, 8947848, 5592405, 2236962, 0, 13880, 26112, 1799168,
  150. 4681808, 2273612, 179713, 5366041, 9756740, 10025880, 16514907, 15063296,
  151. 15121932, 15045888, 16740352, 16726276, 15007744, 13510969, 16728426,
  152. 10420224, 7012352, 16741727, 10512962, 6503455, 10048269, 12275456,
  153. 16762015, 16768972, 16754641, 13594340, 8201933, 15468780, 8519808, 3342455,
  154. 132963, 5308671, 234, 281599, 23457, 6652879, 3586815, 33735, 54237,
  155. 4587464, 11921646,
  156. ];
  157. static STATIC_INDEX = [
  158. 0, 1, 2, 3, 4, 5, 39, 6, 49, 40, 7, 8, 9, 10, 41, 11, 12, 13, 14, 42, 21,
  159. 20, 43, 44, 19, 18, 23, 15, 17, 16, 22, 24, 25, 26, 27, 45, 28, 29, 46, 31,
  160. 30, 32, 33, 47, 34, 35, 36, 37, 38, 48,
  161. ];
  162. initalizePalette(type) {
  163. if (type == undefined) {
  164. type = MMXOPalette.PALETTE_LOAD_STATIC;
  165. MMXOLogger.warning(
  166. "MMXOPalette invoked without specifying the loading type."
  167. );
  168. }
  169. MMXOLogger.info(
  170. "MMXOPalette loading with type: " +
  171. (type == MMXOPalette.PALETTE_LOAD_DYNAMIC ? "DYNAMIC" : "STATIC")
  172. );
  173. if (type == MMXOPalette.PALETTE_LOAD_DYNAMIC) {
  174. const palette = document.getElementById("palette-buttons");
  175. if (!palette) {
  176. MMXOLogger.error(
  177. "Palette requested to be loaded dynamically but HTML is not loaded yet."
  178. );
  179. }
  180. this.colors = [];
  181. this.indexes = [];
  182. const palette_buttons = Array.from(palette.children);
  183. MMXOLogger.info("Dynamic loading found these DOM elements:");
  184. console.log(palette_buttons);
  185. for (const palette_button of palette_buttons) {
  186. const color = {
  187. hex: palette_button.getAttribute("title"),
  188. index: palette_button.getAttribute("data-id"),
  189. };
  190.  
  191. this.colors.push(MMXOPalette.hexStrToHex(color.hex));
  192. this.indexes.push(parseInt(color.index));
  193. }
  194. } else {
  195. this.colors = MMXOPalette.STATIC_COLORS;
  196. this.indexes = MMXOPalette.STATIC_INDEX;
  197. }
  198. }
  199. getIndex(x) {
  200. if (x instanceof Array) {
  201. const [r, g, b] = x;
  202. const hex = (r << 16) | (g << 8) | b;
  203. return this.indexes[this.colors.indexOf(hex)] ?? -1;
  204. } else if (typeof x == "number") {
  205. return this.indexes[this.colors.indexOf(x)] ?? -1;
  206. } else {
  207. MMXOLogger.error("Argument is neither type of Array nor a number");
  208. }
  209. }
  210. constructor(type) {
  211. this.colors = undefined;
  212. this.indexes = undefined;
  213. this.initalizePalette(type);
  214. }
  215. }
  216.  
  217. class MMXOOriginalWebSocket extends WebSocket {}
  218.  
  219. class MMXOWS {
  220. constructor(mmxoPalette, webSocket) {
  221. if (webSocket) {
  222. this.ws = webSocket;
  223. if (mmxoPalette) {
  224. this.mmxoMapCache = new MMXOMapCache(mmxoPalette, this.ws);
  225. this.mmxoMapCache.addPixelChangeListener(this);
  226. }
  227. } else {
  228. this.ws = undefined;
  229. var proxy = this;
  230. this.hook = class extends WebSocket {
  231. constructor(a, b) {
  232. super(a, b);
  233. MMXOLogger.info("MMXOWS has hooked the game WebSocket connection.");
  234. proxy.ws = this;
  235. proxy.mmxoMapCache.addPixelChangeListener(proxy);
  236. }
  237. };
  238. if (typeof unsafeWindow !== undefined) {
  239. if (unsafeWindow.WebSocket != MMXOWS) {
  240. unsafeWindow.WebSocket = this.hook;
  241. }
  242. }
  243. this.mmxoMapCache = new MMXOMapCache(mmxoPalette, this);
  244. }
  245. }
  246. }
  247.  
  248. var map_cache;
  249. class MMXOMapCache {
  250. init(mmxoPalette, mmxoWS) {
  251. var canvas_id = parseInt(location.pathname.replace("/", "").split("-")[0]);
  252. var url = `https://pixelplace.io/canvas/${canvas_id}.png?a=${
  253. Math.floor(Math.random() * 1e9) + 1e9
  254. }`;
  255. var canvas_image = new Image();
  256. var spare_canvas = document.createElement("canvas");
  257. this.before_poll = [];
  258. this.cache = map_cache;
  259. if (this.cache) return;
  260. spare_canvas.ctx = spare_canvas.getContext("2d");
  261. canvas_image.onload = () => {
  262. MMXOLogger.info("Map loaded");
  263. this.map_width = canvas_image.naturalWidth;
  264. this.map_height = canvas_image.naturalHeight;
  265. spare_canvas.width = this.map_width;
  266. spare_canvas.height = this.map_height;
  267. spare_canvas.ctx.drawImage(
  268. canvas_image,
  269. 0,
  270. 0,
  271. this.map_width,
  272. this.map_height
  273. );
  274. var data = spare_canvas.ctx.getImageData(
  275. 0,
  276. 0,
  277. this.map_width,
  278. this.map_height
  279. ).data;
  280. this.cache = new Int8Array(this.map_width * this.map_height);
  281. for (let i = 0; i < data.length; i += 4) {
  282. // slice is slower in custom arrays such as Int8Array
  283. var r = data[i];
  284. var g = data[i + 1];
  285. var b = data[i + 2];
  286. const i_color = mmxoPalette.getIndex([r, g, b]);
  287. this.cache[i >> 2] = i_color;
  288. }
  289. for (let packet of this.before_poll) {
  290. this.cache[packet[0]] = packet[1];
  291. }
  292. this.before_poll = undefined;
  293. };
  294. canvas_image.src = url;
  295. }
  296. constructor(mmxoPalette, mmxoWS) {
  297. this.init(mmxoPalette, mmxoWS);
  298. }
  299. getPixel(x, y) {
  300. var i = y * this.map_width + x;
  301. return this.cache[i];
  302. }
  303. addPixelChangeListener(mmxoWS) {
  304. mmxoWS.ws.addEventListener("message", (e) => {
  305. var data = e.data;
  306. if (!data.startsWith('42["p",')) {
  307. return;
  308. }
  309. var packets = JSON.parse(data.replace("42", ""))[1];
  310. for (let packet of packets) {
  311. var [x, y, color] = packet;
  312. var i = this.map_width * y + x;
  313. if (this.cache) {
  314. this.cache[i] = color;
  315. } else {
  316. this.before_poll.push([i, color]);
  317. }
  318. }
  319. });
  320. }
  321. }
  322.  
  323. class MMXOImagePicker {
  324. static requestImageFromFileDialog(MMXOPalette) {
  325. return new Promise((resolve) => {
  326. const input = document.createElement("input");
  327. input.type = "file";
  328. input.accept = "image/*";
  329. input.click();
  330. input.addEventListener("change", function () {
  331. const reader = new FileReader();
  332. reader.onload = function (e) {
  333. MMXOLogger.info("Image loaded");
  334. resolve(new MMXOImage(e.target.result, MMXOPalette));
  335. };
  336. if (input.files && input.files[0]) {
  337. reader.readAsDataURL(input.files[0]);
  338. }
  339. });
  340. });
  341. }
  342. static addClipboardListener(MMXOPalette, callback) {
  343. document.addEventListener("paste", function (paste_e) {
  344. var items = (paste_e.clipboardData || paste_e.originalEvent.clipboardData)
  345. .items;
  346. MMXOLogger.info(
  347. "Recieved data from clipboard: " + JSON.stringify(items)
  348. );
  349. var blob = null;
  350. for (var i = 0; i < items.length; i++) {
  351. if (items[i].type.indexOf("image") === 0) {
  352. blob = items[i].getAsFile();
  353. }
  354. }
  355. if (blob !== null) {
  356. var reader = new FileReader();
  357. reader.onload = function (e) {
  358. MMXOLogger.info("Readed image from clipboard!");
  359. callback(new MMXOImage(e.target.result, MMXOPalette));
  360. };
  361. reader.readAsDataURL(blob);
  362. }
  363. });
  364. }
  365. }
  366.  
  367. function MMXOWaitForElm(selector) {
  368. return new Promise((resolve) => {
  369. if (document.querySelector(selector)) {
  370. return resolve(document.querySelector(selector));
  371. }
  372.  
  373. const observer = new MutationObserver((mutations) => {
  374. if (document.querySelector(selector)) {
  375. resolve(document.querySelector(selector));
  376. observer.disconnect();
  377. }
  378. });
  379.  
  380. observer.observe(document.body, {
  381. childList: true,
  382. subtree: true,
  383. });
  384. });
  385. }
  386.  
  387. function MMXOCreateWorker(code) {
  388. var blob = new Blob([code], { type: "text/javascript" });
  389.  
  390. var url = URL.createObjectURL(blob);
  391.  
  392. var worker = new Worker(url);
  393. return worker;
  394. }
  395.  
  396. class MMXOImage {
  397. constructor(x, palette) {
  398. this.MMXOPalette = palette;
  399. this.image = undefined;
  400. this.image_canvas = document.createElement("canvas");
  401. this.image_context = this.image_canvas.getContext("2d");
  402. if (x instanceof Image) {
  403. this.image = x;
  404. } else if (typeof x == "string") {
  405. this.image = new Image();
  406. this.image.src = x;
  407. }
  408. if (this.image == undefined) {
  409. MMXOLogger.error("Argument is neither type of Image nor a string");
  410. }
  411. this.image_context.mozImageSmoothingEnabled = false;
  412. this.image.onload = () => {
  413. this.image_canvas.width = this.image.width;
  414. this.image_canvas.height = this.image.height;
  415. this.image_context.drawImage(this.image, 0, 0);
  416. this.image_data = this.image_context.getImageData(
  417. 0,
  418. 0,
  419. this.image_canvas.width,
  420. this.image_canvas.height
  421. );
  422. MMXOLogger.info('Dithering loaded image!');
  423. this.image_data = MMXOImageConverter.floydSteinberg(this.image_data, this.image.width, this.image.height, palette);
  424. };
  425. }
  426. convertToTasks(sx, sy, mmxoWS) {
  427. if (typeof sx != "number" || typeof sy != "number") {
  428. MMXOLogger.error(
  429. "Tried to convert an image to tasks yet the starting coordinates are not a number."
  430. );
  431. }
  432. if (!(mmxoWS instanceof MMXOWS)) {
  433. MMXOLogger.error(
  434. "MMXOImage.convertToTasks requires an MMXOWS in new versions. Please update your code."
  435. );
  436. }
  437. var _tasks = [];
  438. for (let i = 0; i < this.image_data.data.length; i += 4) {
  439. var [r, g, b, a] = this.image_data.data.slice(i, i + 4);
  440. if (a == 0) {
  441. continue;
  442. }
  443. var x = (i / 4) % this.image_data.width;
  444. var y = Math.floor(i / 4 / this.image_data.width);
  445. var colorIndex = this.MMXOPalette.getIndex([r, g, b]);
  446. const c_color = mmxoWS.mmxoMapCache.getPixel(sx + x, sy + y);
  447. if (colorIndex == -1) {
  448. console.log([r, g, b]);
  449. }
  450. if (c_color == colorIndex || c_color == -1 || colorIndex == -1) {
  451. continue;
  452. }
  453. _tasks.push([sx + x, sy + y, colorIndex]);
  454. }
  455. return _tasks;
  456. }
  457. }
  458.  
  459. class MMXOEngine {
  460. static convertToTask(x, y, colorIndex, packetType) {
  461. if (packetType == undefined) {
  462. packetType = 1;
  463. }
  464. return `42["p",${JSON.stringify([x, y, colorIndex, packetType])}]`;
  465. }
  466. putPixel(x, y, colorIndex) {
  467. this.tasks.push([x, y, colorIndex]);
  468. }
  469. putPixelWithPriority(x, y, colorIndex) {
  470. this.tasks.unshift([x, y, colorIndex]);
  471. }
  472. constructor(MMXOWS, timeout) {
  473. if (!MMXOWS || !timeout) {
  474. return;
  475. }
  476. this.tasks = [];
  477. this.MMXOWS = MMXOWS;
  478. this.intervalID = setInterval(() => {
  479. const task = this.tasks.shift();
  480. if (!task) {
  481. return;
  482. }
  483. if (this.MMXOWS.mmxoMapCache.getPixel(task[0], task[1]) == task[2]) {
  484. return;
  485. }
  486. this.MMXOWS.ws.send(MMXOEngine.convertToTask(...task));
  487. }, timeout);
  488. }
  489. }
  490.  
  491. class MMXOEngineMultiBot extends MMXOEngine {
  492. static getAccountDetailsFromCookie(cookie) {
  493. const dict = cookie
  494. .split("; ")
  495. .map((a) => a.split("="))
  496. .reduce(function (b, a) {
  497. if (!["authKey", "authToken", "authId"].includes(a[0])) return b;
  498. b[a[0]] = a[1];
  499. return b;
  500. }, {});
  501. return [dict.authId, dict.authToken, dict.authKey];
  502. }
  503. addAccountFromCookies(authId, authToken, authKey) {
  504. if (!authId || !authToken || !authKey) {
  505. MMXOLogger.warning(
  506. "Auth informations are not defined. (Maybe not logged in?)"
  507. );
  508. return;
  509. }
  510. const boardId = parseInt(location.pathname.replace("/", "").split("-")[0]);
  511. const socket = new MMXOOriginalWebSocket(
  512. "wss://pixelplace.io/socket.io/?EIO=3&transport=websocket"
  513. );
  514. socket.headless = true;
  515. socket.onmessage = ({ data }) => {
  516. const [code, msg] = data.split(/(?<=^\d+)(?=[^\d])/);
  517. if (code == "40") {
  518. socket.send(
  519. "42" +
  520. JSON.stringify(["init", { authKey, authToken, authId, boardId }])
  521. );
  522. }
  523.  
  524. const message = JSON.parse(msg || "[]");
  525. if (message.pingInterval)
  526. socket.ping = setInterval(() => socket.send("2"), message.pingInterval);
  527.  
  528. if (!message.length) return arguments;
  529. const [event, json] = message;
  530. if (event == "throw.error") {
  531. socket.close();
  532. MMXOLogger.error(json);
  533. }
  534. };
  535. socket.onclose = () => {
  536. MMXOLogger.info("User Disconnected");
  537. };
  538. const mmxoWS = new MMXOWS(undefined, socket);
  539. this.sockets.push(mmxoWS);
  540. }
  541. addAccountFromMMXOWS(mmxoWS) {
  542. this.sockets.push(mmxoWS);
  543. }
  544. constructor(timeout, mmxoPalette) {
  545. super();
  546. this.tasks = [];
  547. this.sockets = [];
  548. this.counter = 0;
  549. function interval() {
  550. if (this.sockets.length == 0) {
  551. setTimeout(interval, 100);
  552. return;
  553. }
  554. const task = this.tasks.shift();
  555. if (!task) {
  556. setTimeout(interval, timeout / this.sockets.length);
  557. return;
  558. }
  559. console.log(this);
  560. this.counter = (this.counter + 1) % this.sockets.length;
  561. this.sockets[this.counter]?.ws?.send(MMXOEngine.convertToTask(...task));
  562. setTimeout(this.interval, timeout / this.sockets.length);
  563. }
  564. interval = interval.bind(this);
  565. interval();
  566. this.interval = interval;
  567. }
  568. }
  569. class MMXOProtect {
  570. constructor(core) {
  571. MMXOLogger.info("MMXOProtect has been opened.");
  572. this.core = core;
  573. this.nimage = undefined;
  574. this.coordinates = undefined;
  575. this.working = false;
  576. this.core.mmxoWS.ws.addEventListener(
  577. "message",
  578. function (e) {
  579. if (!this.working) return;
  580. if (!this.nimage) return;
  581. if (!this.coordinates) return;
  582. var data = e.data;
  583. if (!data.startsWith('42["p",')) {
  584. return;
  585. }
  586. var packets = JSON.parse(data.replace("42", ""))[1];
  587. for (let packet of packets) {
  588. var [x, y, color] = packet;
  589. var image_width = this.nimage.image.width;
  590. var image_height = this.nimage.image.height;
  591. var image_x = this.coordinates[0];
  592. var image_y = this.coordinates[1];
  593. var image_xmax = image_width + image_x;
  594. var image_ymax = image_height + image_y;
  595. if (!this.nimage) {
  596. continue;
  597. }
  598. if (
  599. x < image_x ||
  600. x >= image_xmax ||
  601. y < image_y ||
  602. y >= image_ymax
  603. ) {
  604. continue;
  605. }
  606. var img_data_index = 4 * (x - image_x + image_width * (y - image_y));
  607. var [r, g, b, a] = this.nimage.image_data.data.slice(
  608. img_data_index,
  609. img_data_index + 4
  610. );
  611. if (a == 0) continue;
  612. var image_color_i = this.core.palette.getIndex([r, g, b]);
  613. if (image_color_i == undefined) {
  614. MMXOLogger.error(
  615. JSON.stringify([[r, g, b], image_color_i, img_data_index])
  616. );
  617. }
  618. if (image_color_i != color) {
  619. this.core.engine.putPixelWithPriority(x, y, image_color_i);
  620. }
  621. }
  622. }.bind(this)
  623. );
  624. }
  625. start() {
  626. this.working = true;
  627. }
  628. stop() {
  629. this.working = false;
  630. }
  631. load(nimage, coordinates) {
  632. this.nimage = nimage;
  633. this.coordinates = coordinates;
  634. }
  635. }
  636.  
  637. class MMXOCore {
  638. async testAccountValidation() {
  639. const req = await fetch(
  640. "https://pixelplace.io/api/get-painting.php?id=7&connected=1"
  641. );
  642. const json = await req.json();
  643. if (json.user.name == "Guest") {
  644. MMXOLogger.warning("User is not logged in!");
  645. } else {
  646. MMXOLogger.info("Logged in as " + json.user.name);
  647. }
  648. }
  649. constructor(options) {
  650. this.testAccountValidation();
  651. this.palette = new MMXOPalette(MMXOPalette.PALETTE_LOAD_STATIC);
  652. // this.accountManager = new MMXOAccountManager();
  653. this.mmxoWS = new MMXOWS(this.palette); //, this.accountManager);
  654. if (options.multibot) {
  655. this.engine = new MMXOEngineMultiBot(options.timeout);
  656. localStorage.mmxoAccounts = localStorage.mmxoAccounts || "[]";
  657. const mmxoAccounts = JSON.parse(localStorage.mmxoAccounts);
  658. unsafeWindow.addThisAccount = function () {
  659. const session_account = MMXOEngineMultiBot.getAccountDetailsFromCookie(
  660. document.cookie
  661. ).join("_AND_");
  662. if (session_account[0] && !mmxoAccounts.includes(session_account)) {
  663. mmxoAccounts.push(session_account);
  664. }
  665. localStorage.mmxoAccounts = JSON.stringify(mmxoAccounts);
  666. };
  667. for (let account of mmxoAccounts) {
  668. const [authId, authToken, authKey] = account.split("_AND_");
  669. if (!authId || !authToken || !authKey) {
  670. console.error(account);
  671. MMXOLogger.error("Local account is corrupted");
  672. }
  673. this.engine.addAccountFromCookies(authId, authToken, authKey);
  674. }
  675. } else {
  676. this.engine = new MMXOEngine(this.mmxoWS, options.timeout);
  677. }
  678. this.picker = MMXOImagePicker;
  679. this.logger = MMXOLogger;
  680. }
  681. }

QingJ © 2025

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