Support reading position from query params

This commit is contained in:
ekzyis 2025-01-03 21:39:07 +01:00
parent 05bc6514d6
commit 909a36d76f
1 changed files with 10 additions and 10 deletions

View File

@ -38,19 +38,18 @@ templ Overlay(lnurl string, lnaddr string) {
<script>
const qr = document.getElementById("qr");
let currentX = 0;
let currentY = 0;
const urlParams = new URLSearchParams(window.location.search);
let queryX = parseInt(urlParams.get('x'));
let queryY = parseInt(urlParams.get('y'));
const [localX,localY] = localStorage.getItem('qrPosition')?.split(',').map(Number) ?? [0,0];
let currentX = !isNaN(queryX) ? queryX : localX;
let currentY = !isNaN(queryY) ? queryY : localY;
qr.style.transform = `translate(${currentX}px, ${currentY}px)`;
let startX = 0;
let startY = 0;
const savedPosition = localStorage.getItem('qrPosition');
if (savedPosition) {
const [x, y] = savedPosition.split(',').map(Number);
currentX = x;
currentY = y;
qr.style.transform = `translate(${currentX}px, ${currentY}px)`;
}
qr.addEventListener("dragstart", (e) => {
startX = e.clientX - currentX;
startY = e.clientY - currentY;
@ -70,6 +69,7 @@ templ Overlay(lnurl string, lnaddr string) {
currentY = e.clientY - startY;
qr.style.transform = `translate(${currentX}px, ${currentY}px)`;
localStorage.setItem('qrPosition', `${currentX},${currentY}`);
window.location.search = `?x=${currentX}&y=${currentY}`
});
</script>
</body>