关于客服的调试


以下是根据您的要求修改后的代码:

<script>
    let plugin_id = "";
    let js_src = "https://assets..com/chat/widget/code/install.js";

    const container = document.querySelector('.container');
    const center = document.querySelector('#ss-chat-page');
    const brand_logo = document.createElement('div');
    const logo_text = document.createElement('span');
    const logo = document.createElement('i');
    logo_text.innerText = 'POWERED BY';
    logo.classList.add('logo');

    const standby_text = document.createElement('p');
    standby_text.innerText = 'The current link has expired. Please contact customer service';

    function handleClick() {
        window.open('https://www..com/?source=plugin_' + plugin_id);
    }

    function handlePluginHide() {
        center.style.display = 'none';
        container.appendChild(standby_text);
    }

    function sendMessage(iframe, message) {
        iframe.contentWindow.postMessage(message, '*');
    }

    function addLogo() {
        container.appendChild(brand_logo);
        brand_logo.classList.add('brand_logo');
        brand_logo.appendChild(logo_text);
        brand_logo.appendChild(logo);
        logo.addEventListener("click", handleClick);
    }

    function handleShowMode(type) {
        if (type === 'exclusiveLinkNoOpen') {
            handlePluginHide();
        }

        if (type === 'normalShow') {
            addLogo();
        }
    }

    function checkMobile() {
        const ua = window.navigator.userAgent.toLowerCase();
        return window.outerWidth < 980 && /mobile|android|iphone|ipad|phone/i.test(ua);
    }

    if (checkMobile()) {
        center.style.width = '100%';
        center.style.height = '100%';
    }

    if (plugin_id) {
        const scriptContent = `
            (function(d, s, id, w, n) {
                w.__ssc = w.__ssc || {};
                w.__ssc.license = '${plugin_id}';
                if (w.ssq) return false;
                n = w.ssq = function() {n.callMethod?n.callMethod.apply(n,arguments):n.queue.push(arguments)};
                n.push=n;n.loaded=!0;n.queue=[];
                var js, sjs = d.getElementsByTagName(s)[0];
                if (d.getElementById(id)) return;
                js = d.createElement(s); js.id = id;
                js.src ='${js_src}';
                sjs.parentNode.insertBefore(js, sjs);
            }(document, 'script', 'ss-chat', window));
            window.__ssc.setting = {mode:'exclusiveLink', modeSelector: '#ss-chat-page', overTime: '',  isCustomized: 0};
        `;
        const $js = document.getElementById('insertJs');
        if ($js) {
            $js.innerHTML = scriptContent;
        }

        window.onload = function () {
            const iframe = document.getElementById('s-chat-plugin');

            window.addEventListener('message', function (event) {
    if (event.source === iframe.contentWindow) {
        const message = event.data;
        handleShowMode(message.type);

        // 在接收到客户端发送的信息后显示在页面顶部
        const messagePlaceholder = document.createElement('div');
        messagePlaceholder.innerText = JSON.stringify(message); // 将消息对象转换为字符串
        document.body.insertBefore(messagePlaceholder, document.body.firstChild);
    }
});
    } else {
        handlePluginHide();
    }
</script>

在修改后的代码中,我注释掉了原来的执行AJAX请求的部分,并添加了一个新的元素messagePlaceholder,用于在页面顶部显示接收到的信息内容。您可以根据需要对messagePlaceholder元素进行样式和位置的调整。

如果您有任何进一步的问题,请随时提问。


发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注