TinyChan

New reply in topic: Random discussions thread

You are not recognized as the original poster of this topic.

:

You are required to fill in a captcha for your first 5 posts. Sorry, but this is required to stop people from posting while drunk. Please be responsible and don't drink and post!
If you receive this often, consider not clearing your cookies.

Please familiarise yourself with the rules and markup syntax before posting.


Replying to Anonymous Z-24…

@662,079
// Event listener for the checkbox
document.getElementById('autoAddCheckbox').addEventListener('change', function() {
    const isChecked = this.checked;
    const inputTextArea = document.getElementById('inputText');
    if (isChecked) {
        // Listen for input events
        inputTextArea.addEventListener('input', handleInput);
    } else {
        // Remove the input event listener
        inputTextArea.removeEventListener('input', handleInput);
    }
});

// Function to handle input events
function handleInput(event) {
    // Get the input text area and its value
    const inputTextArea = document.getElementById('inputText');
    const inputText = inputTextArea.value.trim();
    // Check if the input is not empty
    if (inputText) {
        // Retrieve existing items from localStorage
        //let jsonArray = JSON.parse(localStorage.getItem('clipboardItems')) || [];
        // Add the new input text to the array
        jsonArray.push(inputText);
        // Update localStorage with the new array
        localStorage.setItem('clipboardItems', JSON.stringify(jsonArray));
        // Clear the input
        inputTextArea.value = '';
        // Refresh the display to show the updated items
        displayItems();
    }
}