smoothretro1982

Tile investigator by haster

Jun 11th, 2026 (edited)
72
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. const edits = new Map();
  2.  
  3. function name(id) {
  4. const cursor = w.cursors.get(id);
  5.  
  6. if (cursor) {
  7. const username = cursor.n || cursor.id || "Anonymous";
  8. return `${username} (${id})`;
  9. }
  10.  
  11. return `${id})`;
  12. }
  13.  
  14. w.socket.addEventListener("message", (e) => {
  15. const edit = network.text(e.data);
  16. if (edit && edit.e) {
  17. const edits_list = edit.e.e;
  18. const client_id = edit.e.clientId;
  19.  
  20. for (let i = 0; i < edits_list.length; i++) {
  21. const chunk = edits_list[i];
  22. const chunk_x = chunk[0];
  23. const chunk_y = chunk[1];
  24.  
  25. for (let j = 0; j < Math.floor((chunk.length - 2) / 3); j++) {
  26. const char_code = chunk[j * 3 + 2];
  27. let index = chunk[j * 3 + 3];
  28. const color = chunk[j * 3 + 4];
  29.  
  30. const char = String.fromCodePoint(char_code);
  31.  
  32. index = ((index % 200) + 200) % 200;
  33.  
  34. const local_row = Math.floor(index / 20);
  35. const local_col = index % 20;
  36.  
  37. const global_x = (chunk_x * 20) + local_col;
  38. const global_y = (chunk_y * 10) + local_row;
  39. const cell_key = `${global_x},${global_y}`;
  40.  
  41. edits.set(cell_key, {
  42. char: char,
  43. color: color,
  44. id: client_id,
  45. name: name(client_id),
  46. timestamp: new Date().toLocaleTimeString()
  47. });
  48. }
  49. }
  50. }
  51. });
  52.  
  53. function who_wrote_char(x, y) {
  54. const cell_key = `${x},${y}`;
  55. const data = edits.get(cell_key);
  56.  
  57. if (!data) {
  58. w.showToast(`No edits recorded for (${x}, ${y})`, 3000);
  59. return null;
  60. }
  61.  
  62. data.name = name(data.id);
  63.  
  64. w.showToast(`(${x}, ${y}): "${data.char}" by ${data.name}`, 4000);
  65.  
  66. return data;
  67. }
  68.  
  69. function start_investigation() {
  70. w.showToast("Click an edit that has been recently updated.", 3000);
  71.  
  72. const target_element = document.body;
  73. const original_cursor = target_element.style.cursor;
  74. target_element.style.cursor = "cell";
  75.  
  76. const handle_canvas_click = (e) => {
  77. e.preventDefault();
  78. e.stopPropagation();
  79.  
  80. const coords = getXYCoordsFromMouseCoords({ pageX: e.pageX, pageY: e.pageY });
  81. who_wrote_char(coords.x, coords.y);
  82.  
  83. target_element.style.cursor = original_cursor;
  84. document.querySelector("canvas").removeEventListener("click", handle_canvas_click, true);
  85. };
  86.  
  87. document.querySelector("canvas").addEventListener("click", handle_canvas_click, true);
  88. }
  89.  
  90. function ui() {
  91. const bubbles_container = document.getElementById("bubbles");
  92. if (!bubbles_container) return;
  93.  
  94. if (document.getElementById("Investigate")) return;
  95.  
  96. const bubble = document.createElement("div");
  97. bubble.title = "Investigate";
  98. bubble.className = "bubble clickable";
  99. bubble.id = "Investigate";
  100. bubble.style = "background-color: rgba(100.0.0.0.8);border: 2px solid rgba(139.0.0.0.6);"
  101.  
  102. const img = document.createElement("img");
  103. img.id = "investigatebtn";
  104. img.alt = "investigate";
  105. img.src = "https://uxwing.com/wp-content/themes/uxwing/download/user-interface/search-magnifying-glass-white-icon.png";
  106. img.style = "width: 22px;height: 202x";
  107. img.className = "nohover";
  108.  
  109. bubble.appendChild(img);
  110. bubbles_container.appendChild(bubble);
  111.  
  112. bubble.addEventListener("click", () => {
  113. start_investigation();
  114. });
  115. }
  116.  
  117. ui();
Tags: tw.2s4.me
Advertisement
Comments
Add Comment
Please, Sign In to add comment