Heatmap for Splix.io

Adds a heatmap feature to the minimap in Splix.io, highlighting recently captured territories in white, which fades to black over time.

安裝腳本?
作者推薦腳本

您可能也會喜歡 Wrong Chat

安裝腳本
  1. // ==UserScript==
  2. // @name Heatmap for Splix.io
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Adds a heatmap feature to the minimap in Splix.io, highlighting recently captured territories in white, which fades to black over time.
  6. // @author fr13ndly
  7. // @license MIT
  8. // @match *://splix.io/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=splix.io
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15.  
  16. const MAX_HEAT_LEVEL = 5;
  17.  
  18. class Heatmap {
  19. constructor() {
  20. this.isInitialUpdate = true;
  21. this.heatCells = [];
  22. }
  23.  
  24. update(cells) {
  25. // HeatCell not found in cells? Remove it.
  26. for (let i = this.heatCells.length; i > 0; i--) {
  27. const heatCell = this.heatCells[i - 1];
  28. const cell = cells.findIndex(
  29. (c) => c.x == heatCell.x && c.y == heatCell.y
  30. );
  31.  
  32. if (cell == -1) {
  33. this.heatCells.splice(i - 1, 1);
  34. }
  35. }
  36. // Update hot levels
  37. for (const cell of cells) {
  38. const heatCell = this.heatCells.find(
  39. (c) => c.x == cell.x && c.y == cell.y
  40. );
  41. if (heatCell) {
  42. if (heatCell.heatLevel > 0) {
  43. heatCell.heatLevel--;
  44. }
  45. continue;
  46. }
  47. // Not found - create "hot" cell
  48. this.heatCells.push({
  49. x: cell.x,
  50. y: cell.y,
  51. heatLevel: this.isInitialUpdate ? 0 : MAX_HEAT_LEVEL,
  52. });
  53. }
  54. this.isInitialUpdate = false;
  55. }
  56.  
  57. get cells() {
  58. return this.heatCells;
  59. }
  60. }
  61.  
  62. class HeatmapUtils {
  63. static getHeatCellColor(heatLevel) {
  64. const lightness = (100 / MAX_HEAT_LEVEL) * heatLevel;
  65. return `hsl(0, 0%, ${lightness}%)`;
  66. }
  67. }
  68.  
  69. var HEATMAPS = {};
  70.  
  71. // Setup custom handlers
  72. window.addEventListener("load", function () {
  73. window.doConnect = new Proxy(window.doConnect, {
  74. apply: (target, thisArg, argArray) => {
  75. const retValue = target.apply(thisArg, argArray);
  76.  
  77. // Modify ws.onmessage handler
  78. if (window.ws) {
  79. window.ws.onmessage = new Proxy(window.ws.onmessage, {
  80. apply: (target, thisArg, argArray) => {
  81. const retValue = target?.apply(thisArg, argArray);
  82.  
  83. heatmapWSMessageHandler.apply(thisArg, argArray);
  84.  
  85. return retValue;
  86. },
  87. });
  88. }
  89.  
  90. return retValue;
  91. },
  92. });
  93. });
  94.  
  95. function heatmapWSMessageHandler(e) {
  96. const m = new Uint8Array(e.data);
  97.  
  98. if (m[0] != receiveAction.MINIMAP) {
  99. return;
  100. }
  101.  
  102. const part = m[1];
  103. const z = 20 * part;
  104.  
  105. if (!HEATMAPS[part]) {
  106. HEATMAPS[part] = new Heatmap();
  107. }
  108.  
  109. const currentHeatmap = HEATMAPS[part];
  110. const partCells = [];
  111.  
  112. // Unpack cells
  113. for (let i = 1; i < m.length; i++) {
  114. // Process each bit
  115. for (let b = 0; b < 8; b++) {
  116. const isBitSet = (m[i] & (1 << b)) !== 0;
  117. if (isBitSet) {
  118. const Q = 8 * (i - 2) + b;
  119. const x = (Math.floor(Q / 80) % 80) + z;
  120. const y = Q % 80;
  121.  
  122. partCells.push({ x, y });
  123. }
  124. }
  125. }
  126.  
  127. // Update heatmap
  128. currentHeatmap.update(partCells);
  129.  
  130. // Clear minimap area
  131. minimapCtx.clearRect(2 * z, 0, 40, 160);
  132. minimapCtx.fillStyle = "#000000";
  133.  
  134. // Render cells
  135. for (const heatCell of currentHeatmap.cells) {
  136. minimapCtx.fillStyle = HeatmapUtils.getHeatCellColor(
  137. heatCell.heatLevel
  138. );
  139. minimapCtx.fillRect(2 * heatCell.x, 2 * heatCell.y, 2, 2);
  140. }
  141. }
  142. })();

QingJ © 2025

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