wip: add hold-to-click on WRITE CODE button for continuous clicking
This commit is contained in:
21
game.js
21
game.js
@@ -3072,6 +3072,27 @@ window.addEventListener('keydown', function (e) {
|
||||
}
|
||||
});
|
||||
|
||||
// Hold-to-click on WRITE CODE button
|
||||
let _holdInterval = null;
|
||||
function _startHold() {
|
||||
if (_holdInterval) return;
|
||||
writeCode(); // immediate first click
|
||||
_holdInterval = setInterval(writeCode, 80); // 12.5 clicks/sec while held
|
||||
}
|
||||
function _stopHold() {
|
||||
if (_holdInterval) { clearInterval(_holdInterval); _holdInterval = null; }
|
||||
}
|
||||
window.addEventListener('DOMContentLoaded', function () {
|
||||
const btn = document.querySelector('.main-btn');
|
||||
if (!btn) return;
|
||||
btn.addEventListener('mousedown', function (e) { e.preventDefault(); _startHold(); });
|
||||
btn.addEventListener('mouseup', _stopHold);
|
||||
btn.addEventListener('mouseleave', _stopHold);
|
||||
btn.addEventListener('touchstart', function (e) { e.preventDefault(); _startHold(); }, { passive: false });
|
||||
btn.addEventListener('touchend', _stopHold);
|
||||
btn.addEventListener('touchcancel', _stopHold);
|
||||
});
|
||||
|
||||
// Ctrl+S to save (must be on keydown to preventDefault)
|
||||
window.addEventListener('keydown', function (e) {
|
||||
if ((e.ctrlKey || e.metaKey) && e.code === 'KeyS') {
|
||||
|
||||
Reference in New Issue
Block a user