dirk1983 / chatgpt

演示站现在可以免费使用ChatGPT对话和画图了。全网最易部署,响应速度最快的ChatGPT环境。PHP版调用OpenAI接口进行问答和画图,采用Stream流模式通信,一边生成一边输出。前端采用EventSource,支持Markdown格式解析,支持公式显示,代码有着色处理,支持画图。页面UI简洁,支持上下文连续会话。源码只有几个文件,没用任何框架,支持所有PHP版本,全部开源,极易二开。保姆级教程,账号等周边资源,欢迎进群交流,一切全免费。

Home Page:https://mm1.ltd

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Weird behavior

airobinnet opened this issue · comments

Weird behavior when you put this in the input:

    <link rel="stylesheet" href="css/common.css?v1.1">
    <link rel="stylesheet" href="css/wenda.css?v1.1">
    <link rel="stylesheet" href="css/hightlight.css">
    <script src="js/remarkable.js"></script>
    <script src="js/jquery-3.6.4.min.js"></script>
    <script src="js/jquery.cookie.min.js"></script>
    <script src="js/layer.min.js"></script>
    <script src="js/chat.js?v2.8"></script>
    <script src="js/highlight.min.js"></script>

if you have an api and you press enter it will keep on submitting
page freezes, looks like it loads all those resources infinitly

this fixes it

function autoresize() {
    var textarea = $('#kw-target');
    var width = textarea.width();
    var content = (textarea.val() + "a").replace(/\\n/g, '<br>');
    var div = $('<div>').css({
        'position': 'absolute',
        'top': '-99999px',
        'border': '1px solid red',
        'width': width,
        'font-size': '15px',
        'line-height': '20px',
        'white-space': 'pre-wrap'
    }).appendTo('body');
    //The issue you're facing is because you're injecting the content into the DOM using the html() method,
    //which causes the browser to parse and execute any script tags present in the content.
    //To prevent this, you can create a text node instead of using the html() method.
    // Create a text node with the content and append it to the div
    var textNode = document.createTextNode(content);
    div[0].appendChild(textNode);


    var height = div.height();
    var rows = Math.ceil(height / 20);
    div.remove();
    textarea.attr('rows', rows);
    $("#article-wrapper").height(parseInt($(window).height()) - parseInt($("#fixed-block").height()) - parseInt($(".layout-header").height()) - 80);
}

even worse, try copy paste this into the demo:
<script> alert("This is very dangerous!"); </script>

thx for the function change! saved my day ... ;)