子比主题评论框增加随机评论内容和按钮,内容随机变换

『点击关注公众号』 关注=免费白嫖,取关=永久拉黑!

效果图:

教程:

1、在子比设置中用户自定义JS代码栏里面填入下面的代码,里面的网址请各位新建一个txt文档,评论内容自定义,一句一行。

// 向评论框输入内容
function insertComment() {
    // 获取文本框中的原有评论内容
    var originalComment = document.getElementsByName("comment")[0];

    // 检测是否有输入
    if (originalComment.value.trim() !== "") {
        originalComment.value = "";
    }

    // 从文本文件中获取随机一行文字
    fetch("https://www..uuxmw.com/pinglun.txt")
        .then(response => response.text())
        .then(data => {
            // 按行拆分文本内容
            var lines = data.split("\n");

            // 随机生成一行序号
            var randomLineIndex = Math.floor(Math.random() * lines.length);

            // 获取随机一行文字,并去除首尾空白字符
            var randomLine = lines[randomLineIndex].trim();

            // 拼接新的评论内容,并换行
            var newComment = originalComment.value + randomLine + "\n";

            // 将新的评论内容更新到文本框中
            originalComment.value = newComment;
        })
        .catch(error => console.error(error));
}

2、找到在子比主题路径template/comments.php找到下面的代码,大概在132行位置,并在其后面添加一行代码就好啦!

if (_pz('comment_img')) {
                    echo zib_get_input_expand_but('image', _pz("comment_upload_img", false), 'comment');
                  }
                  ?>
<a href="#" onclick="insertComment(); return false;">随机评论</a>

原文链接路人粉

泼天的富贵轮到你啦: 大流量卡,官方可查,长期套餐!免费加盟我们,推广还可赚取高额佣金!点击查看详情~
THE END
点赞9 分享
神评区域 抢沙发

请登录后发表评论

    暂无评论内容