MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / onDoublePress

Function onDoublePress

scripts/magnify_image.js:1418–1443  ·  view source on GitHub ↗
(key, callback, timeout = 500)

Source from the content-addressed store, hash-verified

1416 };
1417}
1418function onDoublePress(key, callback, timeout = 500) {
1419 let timer = null;
1420 let clickCount = 0;
1421 const keyup = (event) => {
1422 if (event.key !== key) {
1423 clickCount = 0;
1424 return;
1425 }
1426 clickCount++;
1427 if (clickCount === 2) {
1428 callback?.();
1429 clickCount = 0;
1430 return;
1431 }
1432 clearTimeout(timer);
1433 timer = setTimeout(() => {
1434 clickCount = 0;
1435 }, timeout);
1436 };
1437
1438 document.addEventListener("keyup", keyup);
1439 return () => {
1440 clearTimeout(timer);
1441 document.removeEventListener("keyup", keyup);
1442 };
1443}
1444function lerp(from, to, speed) {
1445 return from + (to - from) * speed;
1446}

Callers 1

magnify_image.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected