document.addEventListener('DOMContentLoaded', function() {
    const PROMPT_DELAY = 10000; // 首次提示延迟时间：10秒
    const PROMPT_INTERVAL = 20000; // 后续提示间隔时间：20秒
    const MAX_PROMPT_COUNT = 3; // 最大提示次数

    let lastPromptTime = 0; // 上次显示提示的时间戳
    let promptCount = 0; // 提示次数计数器
    let promptTimer; // 定时器，用于控制首次提示的延迟

    function isTouchDevice() {
        return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
    }

    function canShowPrompt() {
        const currentTime = Date.now();
        return currentTime - lastPromptTime > PROMPT_INTERVAL && promptCount < MAX_PROMPT_COUNT;
    }

    function showPrompt() {
        if (canShowPrompt()) {
            lastPromptTime = Date.now();
            promptCount++;

            const userConfirmed = confirm("为了更好的服务您，立即与我们联系！电话：15072487941（微信同号）");
            if (userConfirmed) {
                window.location.href = 'tel:15072487941';
            }

            if (promptCount >= MAX_PROMPT_COUNT) {
                document.removeEventListener('touchstart', showPrompt);
            }
        }
    }

    if (isTouchDevice()) {
        // 设置首次提示的延迟
        promptTimer = setTimeout(() => {
            document.addEventListener('touchstart', showPrompt);
        }, PROMPT_DELAY);
    }

    // 禁用右键菜单
    document.addEventListener('contextmenu', function(event) {
        event.preventDefault();
    });

    // 禁用特定快捷键
    document.addEventListener('keydown', function(event) {
        const ctrlKeys = ['u', 'c', 'a'];
        if (event.ctrlKey && (ctrlKeys.includes(event.key) || (event.shiftKey && event.key === 'u'))) {
            event.preventDefault();
        }
    });

    // 防止图像被拖拽下载
    document.addEventListener('dragstart', function(event) {
        if (event.target.tagName.toLowerCase() === 'img') {
            event.preventDefault();
        }
    });
});