Created
November 29, 2024 20:15
-
-
Save nietaki/b5148882335cce51c023ec3721750df5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function to simulate mouse movement | |
function simulateMouseMovement(canvas, x, y) { | |
var evt = new MouseEvent('mousemove', { | |
bubbles: true, | |
cancelable: true, | |
view: window, | |
clientX: x, | |
clientY: y, | |
screenX: x, | |
screenY: y, | |
movementX: 0, | |
movementY: 0 | |
}); | |
var rect = canvas.getBoundingClientRect(); | |
var gwtEvent = { | |
type: 'mousemove', | |
clientX: x + rect.left, | |
clientY: y + rect.top, | |
stopPropagation: function() {}, | |
preventDefault: function() {} | |
}; | |
canvas.dispatchEvent(evt); | |
if (canvas.__gwt_listener) { | |
canvas.__gwt_listener(gwtEvent); | |
} | |
if (canvas.parentElement && canvas.parentElement.__gwt_listener) { | |
canvas.parentElement.__gwt_listener(gwtEvent); | |
} | |
} | |
function scanVisibleArea() { | |
const coordsLabel = document.querySelector('.coordsLabel'); | |
if (!coordsLabel) { | |
console.error('Coordinates label not found'); | |
return; | |
} | |
let lastCoords = null; | |
const rect = canvas.getBoundingClientRect(); | |
const visibleArea = { | |
left: Math.max(0, rect.left), | |
top: Math.max(0, rect.top), | |
right: Math.min(window.innerWidth, rect.right), | |
bottom: Math.min(window.innerHeight, rect.bottom) | |
}; | |
function scanPoint(x, y) { | |
return new Promise(resolve => { | |
const canvasX = x - rect.left; | |
const canvasY = y - rect.top; | |
simulateMouseMovement(canvas, canvasX, canvasY); | |
setTimeout(() => { | |
const currentCoords = coordsLabel.textContent; | |
if (currentCoords !== lastCoords) { | |
console.log(`Viewport Position (${x}, ${y}), Canvas Position (${canvasX}, ${canvasY}): ${currentCoords}`); | |
lastCoords = currentCoords; | |
} | |
resolve(); | |
}, 10); | |
}); | |
} | |
async function scanVisiblePoints() { | |
const stepSize = 10; | |
for (let y = visibleArea.top; y < visibleArea.bottom; y += stepSize) { | |
for (let x = visibleArea.left; x < visibleArea.right; x += stepSize) { | |
if (x >= rect.left && x <= rect.right && | |
y >= rect.top && y <= rect.bottom) { | |
await scanPoint(x, y); | |
} | |
} | |
} | |
console.log('Visible area scan complete'); | |
} | |
console.log('Starting scan of visible area:', visibleArea); | |
scanVisiblePoints(); | |
} | |
// Start the scan | |
scanVisibleArea(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment