From cd484263e0f850cb276fa9db83c54a236005e8af Mon Sep 17 00:00:00 2001 From: peshomir <80340328+peshomir@users.noreply.github.com> Date: Sun, 4 Aug 2024 09:51:50 +0300 Subject: [PATCH] Fix for the the hovering tooltip on mobile, again --- src/fx_core.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/fx_core.js b/src/fx_core.js index db2db9f..7ea611e 100644 --- a/src/fx_core.js +++ b/src/fx_core.js @@ -500,15 +500,27 @@ const hoveringTooltip = new (function() { this.canvasPixelScale = 1; function handler(e) { if (!settings.hoveringTooltip || !getVar("gameState") || recentlyShown) return; + let x, y; + // https://stackoverflow.com/a/61732450 + if (e.type.includes(`touch`)) { + const { touches, changedTouches } = e.originalEvent ?? e; + const touch = touches[0] ?? changedTouches[0]; + x = touch.pageX; + y = touch.pageY; + } else if (e.type.includes(`mouse`)) { + x = e.clientX; + y = e.clientY; + } + recentlyShown = true; try { - this.display(this.canvasPixelScale * e.clientX, this.canvasPixelScale * e.clientY); + this.display(this.canvasPixelScale * x, this.canvasPixelScale * y); } catch (e) { console.error(e) } // for better performance, reduce the tooltip display frequency to no more than once every 100 ms setTimeout(() => recentlyShown = false, 100); } document.getElementById("canvasA").addEventListener("mousemove", handler.bind(this)); - document.getElementById("canvasA").addEventListener("touchmove", handler.bind(this)); + document.getElementById("canvasA").addEventListener("touchstart", handler.bind(this)); }); var donationsTracker = new (function(){