mirror of
https://github.com/nirvana-7777/script.service.ultimate.git
synced 2026-09-16 14:12:20 +02:00
15 lines
472 B
JavaScript
15 lines
472 B
JavaScript
// Debounce utility for auto-save
|
|
function debounce(func, wait, immediate) {
|
|
let timeout;
|
|
return function() {
|
|
const context = this, args = arguments;
|
|
const later = function() {
|
|
timeout = null;
|
|
if (!immediate) func.apply(context, args);
|
|
};
|
|
const callNow = immediate && !timeout;
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(later, wait);
|
|
if (callNow) func.apply(context, args);
|
|
};
|
|
} |