/**
 * 小栈AI综合助手 V5 - AI 摘要打字机动画
 */
(function() {
    'use strict';

    function initTypewriter() {
        var el = document.querySelector('.XZDAI-explanation[data-summary]');
        if (!el) return;

        var text = el.getAttribute('data-summary');
        if (!text) return;

        var cursor = el.querySelector('.blinking-cursor');
        var index = 0;
        var speed = 60;

        function type() {
            if (index < text.length) {
                el.textContent = text.substring(0, index + 1);
                var span = document.createElement('span');
                span.className = 'blinking-cursor';
                el.appendChild(span);
                index++;
                setTimeout(type, speed);
            } else {
                var tag = document.querySelector('.XZDAI-tag.loading-xzdai');
                if (tag) tag.classList.remove('loading-xzdai');
                if (cursor) cursor.remove();
            }
        }

        type();
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', initTypewriter);
    } else {
        initTypewriter();
    }
})();
