<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>安全验证</title>
<style>
body{
    margin:0;
    background:#f3f3f3;
    font-family:Arial,"Microsoft YaHei",sans-serif;
}
.verify-wrap{
    width:360px;
    max-width:92%;
    margin:120px auto;
    background:#fff;
    border-radius:12px;
    box-shadow:0 4px 18px rgba(0,0,0,.08);
    padding:24px;
}
.verify-title{
    font-size:20px;
    font-weight:bold;
    margin-bottom:10px;
}
.verify-desc{
    color:#666;
    margin-bottom:20px;
    font-size:14px;
}
.slider-box{
    position:relative;
    height:52px;
    background:#eee;
    border-radius:26px;
    overflow:hidden;
    user-select:none;
}
.slider-track{
    position:absolute;
    left:0;
    top:0;
    height:100%;
    width:0;
    background:#d7f0d9;
    border-radius:26px;
    transition:width .05s linear;
}
.slider-text{
    position:absolute;
    width:100%;
    height:100%;
    line-height:52px;
    text-align:center;
    color:#666;
    font-size:15px;
    z-index:2;
}
.slider-btn{
    position:absolute;
    left:0;
    top:0;
    width:52px;
    height:52px;
    background:#fff;
    border-radius:50%;
    box-shadow:0 2px 8px rgba(0,0,0,.18);
    cursor:pointer;
    z-index:3;
}
.slider-btn:before{
    content:"»";
    display:block;
    text-align:center;
    line-height:52px;
    font-size:22px;
    color:#666;
}
.ok{
    color:#1f8f3a !important;
}
</style>
</head>
<body>
<div class="verify-wrap">
    <div class="verify-title">安全验证</div>
    <div class="verify-desc">请滑动到最右侧完成验证</div>

    <div class="slider-box" id="sliderBox">
        <div class="slider-track" id="sliderTrack"></div>
        <div class="slider-text" id="sliderText">向右滑动完成验证</div>
        <div class="slider-btn" id="sliderBtn"></div>
    </div>
</div>

<script>
(function(){
    const sliderBox = document.getElementById('sliderBox');
    const sliderBtn = document.getElementById('sliderBtn');
    const sliderTrack = document.getElementById('sliderTrack');
    const sliderText = document.getElementById('sliderText');

    let dragging = false;
    let startX = 0;
    let startLeft = 0;
    let maxLeft = sliderBox.offsetWidth - sliderBtn.offsetWidth;
    let passed = false;

    function getClientX(e){
        return e.touches ? e.touches[0].clientX : e.clientX;
    }

    function startDrag(e){
        if (passed) return;
        dragging = true;
        startX = getClientX(e);
        startLeft = sliderBtn.offsetLeft;
        e.preventDefault();
    }

    function moveDrag(e){
        if (!dragging || passed) return;
        let x = getClientX(e);
        let move = x - startX;
        let left = startLeft + move;

        if (left < 0) left = 0;
        if (left > maxLeft) left = maxLeft;

        sliderBtn.style.left = left + 'px';
        sliderTrack.style.width = (left + sliderBtn.offsetWidth / 2) + 'px';

        if (left >= maxLeft - 2) {
            passed = true;
            dragging = false;
            sliderBtn.style.left = maxLeft + 'px';
            sliderTrack.style.width = sliderBox.offsetWidth + 'px';
            sliderText.textContent = '验证成功，正在跳转...';
            sliderText.classList.add('ok');
            submitVerify();
        }
    }

    function endDrag(){
        if (!dragging || passed) return;
        dragging = false;
        sliderBtn.style.left = '0px';
        sliderTrack.style.width = '0px';
    }

    function submitVerify(){
        fetch('/verify_check.php', {
            method: 'POST',
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            body: 'pass=1'
        })
        .then(res => res.json())
        .then(data => {
            if (data && data.success) {
                location.href = data.redirect || '/';
            } else {
                alert('验证失败，请重试');
                location.reload();
            }
        })
        .catch(() => {
            alert('网络错误，请重试');
            location.reload();
        });
    }

    sliderBtn.addEventListener('mousedown', startDrag);
    document.addEventListener('mousemove', moveDrag);
    document.addEventListener('mouseup', endDrag);

    sliderBtn.addEventListener('touchstart', startDrag, {passive:false});
    document.addEventListener('touchmove', moveDrag, {passive:false});
    document.addEventListener('touchend', endDrag);

    window.addEventListener('resize', function(){
        maxLeft = sliderBox.offsetWidth - sliderBtn.offsetWidth;
    });
})();
</script>
</body>
</html>