Skip to content

Commit

Permalink
fix de #139 avec ajout de clickWithRefractoryPeriod
Browse files Browse the repository at this point in the history
  • Loading branch information
Refhi committed Jun 21, 2024
1 parent 8bd4f41 commit 9647ff6
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions keyCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,31 @@ function GenericClicker(valueName, value) {
}
}

// Clique sur un bouton et inhibe les clics trop rapides
var lastClickTime = 0;
function clickWithRefractoryPeriod(element) {
var currentTime = new Date().getTime();
var timeSinceLastClick = currentTime - lastClickTime;

if (timeSinceLastClick >= 200) {
element.click();
recordMetrics({ clicks: 1, drags: 1 });
console.log('Element clicked:', element);
lastClickTime = currentTime;
} else {
console.log('Clicking too fast, waiting', 200 - timeSinceLastClick, 'ms');
setTimeout(function() {
lastClickTime = new Date().getTime();
}, 200 - timeSinceLastClick);
}
}


// Clique sur un bouton selon son Id
function clickElementById(elementId) {
var element = document.getElementById(elementId);
if (element) {
element.click();
recordMetrics({ clicks: 1, drags: 1 });
console.log('Element clicked:', elementId);
clickWithRefractoryPeriod(element); // Utilise une période réfractaire pour éviter les clics trop rapides
return true;
} else {
console.log('Element not found:', elementId);
Expand Down

0 comments on commit 9647ff6

Please sign in to comment.