Home / Widgets / Untitled Snippet
Duplicate Snippet

Embed Snippet on Your Site

Untitled Snippet

Code Preview
php
<?php
function getChatContent() {
  const chat =
    document.querySelector('.mwai-chatbot .mwai-messages') ||
    document.querySelector('.mwai-chatbot');
  return chat ? chat.innerHTML : '';
}
function getChatText() {
  const chat =
    document.querySelector('.mwai-chatbot .mwai-messages') ||
    document.querySelector('.mwai-chatbot');
  return chat ? chat.innerText : '';
}
function buildPDFHtml(content) {
  return `
  <html>
    <head>
      <meta charset="UTF-8" />
      <style>
        body {
          font-family: Arial, sans-serif;
          padding: 40px;
          line-height: 1.6;
        }
        img {
          max-width: 160px;
          margin-bottom: 20px;
        }
        h1 {
          font-size: 22px;
          margin-bottom: 20px;
        }
        .chat {
          font-size: 14px;
        }
      </style>
    </head>
    <body>
      <img src="https://nosfui.com/wp-content/uploads/2023/07/logo-3-png-scaled.webp" />
      <h1>Your Travel Plan</h1>
      <div class="chat">
        ${content}
      </div>
    </body>
  </html>`;
}
function downloadPDF() {
  const content = getChatContent();
  if (!content) {
    alert('Generate a plan first.');
    return;
  }
  const win = window.open('', '', 'width=900,height=700');
  win.document.write(buildPDFHtml(content));
  win.document.close();
  win.focus();
  win.print();
}
function shareResult() {
  const text = getChatText();
  if (!text) {
    alert('Generate a plan first.');
    return;
  }
  if (navigator.share) {
    navigator.share({
      title: 'My Travel Plan',
      text: text
    });
  } else {
    navigator.clipboard.writeText(text);
    alert('Copied to clipboard');
  }
}

Comments

Add a Comment