<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        const whiteList = ['beian.miit.gov.cn', 'www.travellings.cn', '*.github.com', 'music.163.com',"*.likesrt.com","*.upyun.com"];  // 白名单主机名
        const currentHost = window.location.host;

        function isWhiteListed(host) {
            return whiteList.some(domain => {
                if (domain.startsWith('*.')) {
                    // 匹配泛域名
                    const baseDomain = domain.slice(2);
                    return host.endsWith(baseDomain);
                } else {
                    return host === domain;
                }
            });
        }

        document.body.addEventListener('click', function (event) {
            let target = event.target;
            while (target && target.tagName !== 'A') {
                target = target.parentElement;
            }

            if (target && target.href) {
                const originalUrl = target.href;
                const linkHost = new URL(originalUrl).host;

                // 检查链接是否在白名单内,或者是本站链接
                if (linkHost && !isWhiteListed(linkHost) && linkHost !== currentHost) {
                    event.preventDefault();
                    showWarningModal(originalUrl);
                }
            }
        }, true);

        function showWarningModal(url) {
            let countdown = 6;
            let intervalId;

            Swal.fire({
                title: `安全提醒:`,
                html: `您即将离开 "云深处" 去往如下网址:<br><strong>${url}</strong><br>请注意您的账号隐私安全和财产安全:<br><strong><span id="countdown">${countdown}</span></strong> 秒后将自动跳转`,
                icon: 'warning',
                showCancelButton: true,
                confirmButtonText: '继续前往',
                cancelButtonText: '返回本站',
                willClose: () => {
                    clearInterval(intervalId);
                },
                scrollbarPadding: false
            }).then((result) => {
                if (result.isConfirmed) {
                    window.open(url, '_blank');
                }
            });

            intervalId = setInterval(() => {
                countdown--;
                document.getElementById('countdown').textContent = countdown;

                if (countdown <= 0) {
                    clearInterval(intervalId);
                    Swal.close();
                    window.open(url, '_blank');
                }
            }, 1000);
        }
    });
</script>