function logToPage(outputContainer, message) {
    // Format timestamp as hh:mm:ss
    const now = new Date();
    const timestamp = now.toTimeString().slice(0, 8);

    var logEntry = document.createElement('p');
    logEntry.className = 'mb-1';
    logEntry.innerHTML = `<span style="color: #666; font-size: 0.85em;">[${timestamp}]</span> ${message}`;
    outputContainer.appendChild(logEntry);

    // Trim old entries to prevent memory leak
    if (typeof window.trimContainer === 'function') {
        window.trimContainer(outputContainer, window.MAX_CONSOLE_ENTRIES || 500);
    }

    // Auto-scroll to the bottom of the container
    outputContainer.scrollTop = outputContainer.scrollHeight;
}

function startTrackingYT(outputContainer) {
    const videoId = document.getElementById('YTvideoId').value;


    // Clear previous output
    //document.getElementById('outputContainer').innerHTML = '';

    // Log initial message
    logToPage(outputContainer, `Started tracking YouTube video: ${videoId}`);

    // Your tracking implementation
    // When you want to log something:
    // logToPage("New update: viewer count changed to 1,500");
}