diff --git a/userscript/manga-bookmark.user.js b/userscript/manga-bookmark.user.js index 607ee13..97aaaa9 100644 --- a/userscript/manga-bookmark.user.js +++ b/userscript/manga-bookmark.user.js @@ -1019,6 +1019,16 @@ fab.style.bottom = "auto"; }); + function snapToEdge() { + const w = fab.offsetWidth, h = fab.offsetHeight; + const r = fab.getBoundingClientRect(); + const side = r.left + w / 2 < window.innerWidth / 2 ? "left" : "right"; + const y = clamp(r.top, FAB_MARGIN, window.innerHeight - h - FAB_MARGIN); + fab.style.transition = "left .2s ease, right .2s ease, top .2s ease"; + applyFabPos(fab, side, y); + saveFabPos(side, y / window.innerHeight); + } + fab.addEventListener("pointerup", (e) => { if (!down) return; const didDrag = moved, didScroll = scrolling; @@ -1029,16 +1039,15 @@ } if (!didDrag) return; // tap — let the click handler toggle the panel fab.dataset.dragged = "1"; // suppress the click that trails this drag - const w = fab.offsetWidth, h = fab.offsetHeight; - const r = fab.getBoundingClientRect(); - const side = r.left + w / 2 < window.innerWidth / 2 ? "left" : "right"; - const y = clamp(r.top, FAB_MARGIN, window.innerHeight - h - FAB_MARGIN); - fab.style.transition = "left .2s ease, right .2s ease, top .2s ease"; - applyFabPos(fab, side, y); - saveFabPos(side, y / window.innerHeight); + snapToEdge(); }); - fab.addEventListener("pointercancel", reset); + fab.addEventListener("pointercancel", () => { + if (!down) return; + const didDrag = moved; + reset(); + if (didDrag) snapToEdge(); // OS claimed the gesture mid-drag — don't strand the FAB + }); } // ============================================================