Untitled

 avatar
unknown
javascript
9 months ago
795 B
7
Indexable
const debounce = (func, delay) => {
    let timeoutId;
    return (...args) => {
        clearTimeout(timeoutId);
        timeoutId = setTimeout(() => {
            func.apply(null, args);
        }, delay);
    };
};

// Function to set up input field backup and restore
function setupInputBackup(inputSelector) {
    const inputField = document.querySelector(inputSelector); // Select the input element
    if (inputField) {
        inputField.addEventListener('input', debounce(() => localStorage.setItem('inputBackup', inputField.value), 300)); // Backup on input with debounce
        inputField.value = localStorage.getItem('inputBackup') || ''; // Restore the input value
    }
}

// Call the function with the selector for the input field
setupInputBackup('.text');
Editor is loading...
Leave a Comment