You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用jQuery添加不可移除版权文本并实现篡改自动重定向?

实现不可移除的版权监测与自动重定向

需求说明

需要在网页页脚添加版权区块,当出现以下任意操作时,网页自动跳转到指定URL:

  • 移除版权代码
  • 通过display:none或visibility:hidden隐藏版权区块
  • 修改版权区块的ID
  • 修改版权区块内的文本内容

原有代码缺陷

  • 第一段代码使用IntersectionObserver监测隐藏/移除,但无法检测版权ID被修改的情况
  • 第二段代码通过定时对比内容和样式,但当版权ID被修改后,无法获取到目标元素,导致监测失效

解决方案代码

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>版权监测示例</title>
</head>
<body>
    <footer>
        <div id="copyright">Copyright © 2024 你的站点名称 | 保留所有权利</div>
    </footer>

    <script>
        // 配置目标跳转URL
        const REDIRECT_URL = 'https://your-target-url.com';
        // 保存版权区块的原始文本内容
        let originalCopyrightText = '';

        // 初始化:获取原始文本
        function init() {
            const copyright = document.getElementById('copyright');
            if (copyright) {
                originalCopyrightText = copyright.textContent.trim();
            } else {
                // 页面加载时就没有版权元素,直接跳转
                location.href = REDIRECT_URL;
            }
        }

        // 版权检查核心函数
        function checkCopyright() {
            const copyright = document.getElementById('copyright');
            
            // 1. 检查copyright ID是否存在
            if (!copyright) {
                location.href = REDIRECT_URL;
                return;
            }

            // 2. 检查版权文本是否被修改
            const currentText = copyright.textContent.trim();
            if (currentText !== originalCopyrightText) {
                location.href = REDIRECT_URL;
                return;
            }

            // 3. 检查版权区块是否被隐藏
            const computedStyle = window.getComputedStyle(copyright);
            const isHidden = computedStyle.display === 'none' || 
                            computedStyle.visibility === 'hidden' ||
                            !copyright.offsetParent; // 判断是否脱离文档流
            if (isHidden) {
                location.href = REDIRECT_URL;
                return;
            }
        }

        // 初始化原始文本
        init();
        // 定时执行检查,间隔1秒可根据需求调整
        setInterval(checkCopyright, 1000);
    </script>
</body>
</html>

代码说明

  • ID存在监测:每次检查都会重新通过getElementById('copyright')获取元素,若ID被修改或元素被移除,直接触发跳转
  • 文本修改监测:初始化时保存版权区块的原始文本,每次检查对比当前文本,不一致则跳转
  • 隐藏状态监测:通过计算样式检查display和visibility属性,同时利用offsetParent判断元素是否脱离文档流(覆盖通过定位、缩放等方式的隐藏)
  • 定时检查:使用setInterval定时执行检查逻辑,间隔可根据需求调整(建议1-3秒,兼顾性能和监测灵敏度)

内容的提问来源于stack exchange,提问作者Asma Binta Younus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 09:55:25