Widget:StartseitenSuche: Unterschied zwischen den Versionen

Aus MediaWiki
Wechseln zu:Navigation, Suche
KKeine Bearbeitungszusammenfassung
KKeine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
<includeonly>
<includeonly>
<style type="text/css">
 
   .perplexity-search {
<div id="chat-widget">
    display: inline-block;
  <div id="chat-messages"></div>
    padding: 10px;
  <div id="chat-sources-panel"></div>
    background-color: #f0f0f0;
  <form id="chat-form">
    border-radius: 5px;
    <input type="text" id="chat-input" placeholder="Stelle eine Frage über Münster …" autocomplete="off" />
     width: max-content;
    <button type="submit" id="chat-send">Fragen</button>
  </form>
  <div id="chat-footer">
    <span id="chat-status"></span>
    <button id="chat-new" type="button">Neue Unterhaltung</button>
   </div>
</div>
 
<style>
#chat-widget {
  max-width: 800px;
  margin: 0 auto;
  font-family: -apple-system, "system-ui", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #212529;
  display: flex;
  flex-direction: column;
}
#chat-messages {
  min-height: 120px;
  max-height: 500px;
  overflow-y: auto;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#chat-messages:empty::before {
  content: "Stelle eine Frage und erhalte Antworten basierend auf dem Münster Wiki und ausgewählten Seiten. Beachte: KI-Suche kann Fehler enthalten. Bitte prüfe die Ergebnisse. Personenbezogenen Daten können zur Optimierung der KI genutzt werden";
  display: block;
  text-align: center;
  color: #999;
  font-size: 14px;
  padding: 40px 16px;
}
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14.5px;
  line-height: 1.55;
  word-wrap: break-word;
}
.chat-msg-user {
  align-self: flex-end;
  background: #00308D;
  color: #fff;
  border-bottom-right-radius: 3px;
}
.chat-msg-assistant {
  align-self: flex-start;
  background: #f0f2f5;
  color: #212529;
  border-bottom-left-radius: 3px;
}
.chat-msg-assistant p {
  margin: 0 0 8px 0;
}
.chat-msg-assistant p:last-child {
  margin-bottom: 0;
}
@keyframes chatDots {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}
.chat-loading-dots span {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 2px;
  background: #999;
  border-radius: 50%;
  animation: chatDots 1.2s ease-in-out infinite;
}
.chat-loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-loading-dots span:nth-child(3) { animation-delay: 0.3s; }
#chat-sources-panel {
  display: none;
}
#chat-sources-panel.visible {
  display: block;
  margin: 4px 0 8px 0;
}
.chat-sources-toggle {
  background: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  color: #555;
  cursor: pointer;
  transition: background 0.15s;
}
.chat-sources-toggle:hover {
  background: #f5f5f5;
}
.chat-sources-list {
  display: none;
  margin-top: 8px;
}
.chat-sources-list.open {
  display: block;
}
.chat-source-item {
  padding: 10px 12px;
  margin-bottom: 6px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: #fff;
  transition: border-color 0.15s;
}
.chat-source-item:hover {
  border-color: #b0b8c1;
}
.chat-source-item h5 {
  margin: 0 0 3px 0;
  font-size: 14px;
  font-weight: 600;
}
.chat-source-item h5 a {
  color: #00308D;
  text-decoration: none;
}
.chat-source-item h5 a:hover {
  text-decoration: underline;
}
.chat-source-item .chat-source-snippet {
  font-size: 12.5px;
  line-height: 1.45;
  color: #666;
  margin: 0;
}
.chat-source-item .chat-source-meta {
  font-size: 11px;
  color: #999;
  margin-top: 3px;
}
#chat-form {
  display: flex;
  margin-top: 8px;
}
#chat-input {
  flex: 1;
  padding: 10px 14px;
  font-size: 15px;
  border: 1px solid #ccc;
  border-right: none;
  border-radius: 4px 0 0 4px;
  outline: none;
  transition: border-color 0.2s;
  color: #212529;
  background: #fff;
}
#chat-input:focus {
  border-color: #4CAF50;
}
#chat-input:disabled {
  background: #f5f5f5;
  color: #999;
}
#chat-send {
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  background: #4CAF50;
  color: #fff;
  border: none;
  border-radius: 0 4px 4px 0;
  transition: background 0.2s;
  white-space: nowrap;
}
#chat-send:hover {
  background: #43A047;
}
#chat-send:disabled {
  background: #a5d6a7;
  cursor: not-allowed;
}
#chat-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  min-height: 28px;
}
#chat-status {
  font-size: 12px;
  color: #888;
}
#chat-new {
  display: none;
  background: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 4px 12px;
  font-size: 12px;
  color: #555;
  cursor: pointer;
  transition: background 0.15s;
}
#chat-new:hover {
  background: #f5f5f5;
}
#chat-new.visible {
  display: inline-block;
}
.chat-msg-error {
  align-self: center;
  background: #fef2f2;
  color: #b00;
  border: 1px solid #fca5a5;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 6px;
}
</style>
 
<script>
(function() {
  var form = document.getElementById('chat-form');
  var input = document.getElementById('chat-input');
  var sendBtn = document.getElementById('chat-send');
  var messagesEl = document.getElementById('chat-messages');
  var sourcesPanel = document.getElementById('chat-sources-panel');
  var statusEl = document.getElementById('chat-status');
  var newBtn = document.getElementById('chat-new');
  var apiHost = 'api.' + location.hostname.split('.').slice(1).join('.');
 
  var conversationId = null;
  var isLoading = false;
 
  function escapeHtml(str) {
    var d = document.createElement('div');
    d.textContent = str;
    return d.innerHTML;
  }
 
  function truncate(str, len) {
    if (str.length <= len) return str;
    return str.substring(0, len).replace(/\s+\S*$/, '') + '\u2026';
  }
 
  function formatAnswer(text) {
    var html = escapeHtml(text);
    html = html.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>');
    var paragraphs = html.split(/\n{2,}/);
    if (paragraphs.length > 1) {
      html = paragraphs.map(function(p) { return '<p>' + p.replace(/\n/g, '<br>') + '</p>'; }).join('');
    } else {
      html = html.replace(/\n/g, '<br>');
    }
    return html;
  }
 
  function addUserMessage(text) {
    var div = document.createElement('div');
    div.className = 'chat-msg chat-msg-user';
    div.textContent = text;
    messagesEl.appendChild(div);
    scrollToBottom();
  }
 
  function addAssistantMessage(text) {
    var div = document.createElement('div');
    div.className = 'chat-msg chat-msg-assistant';
    div.innerHTML = formatAnswer(text);
    messagesEl.appendChild(div);
    scrollToBottom();
  }
 
  function addLoadingIndicator() {
    var div = document.createElement('div');
    div.className = 'chat-msg chat-msg-assistant chat-loading-dots';
    div.id = 'chat-loading';
    div.innerHTML = '<span></span><span></span><span></span>';
    messagesEl.appendChild(div);
    scrollToBottom();
  }
 
  function removeLoadingIndicator() {
    var el = document.getElementById('chat-loading');
    if (el) el.remove();
  }
 
  function addError(msg) {
    var div = document.createElement('div');
    div.className = 'chat-msg chat-msg-error';
    div.textContent = msg;
    messagesEl.appendChild(div);
    scrollToBottom();
  }
 
  function scrollToBottom() {
    messagesEl.scrollTop = messagesEl.scrollHeight;
  }
 
  function renderSources(sources) {
    if (!sources || sources.length === 0) {
      sourcesPanel.className = '';
      sourcesPanel.innerHTML = '';
      return;
    }
    sourcesPanel.className = 'visible';
    var listId = 'src-list-' + Date.now();
     var html = '<button class="chat-sources-toggle" onclick="var l=document.getElementById(\'' + listId + '\');l.classList.toggle(\'open\');this.textContent=l.classList.contains(\'open\')?\'▲ Quellen verbergen\':\'▼ ' + sources.length + ' Quellen anzeigen\'">'
      + '▼ ' + sources.length + ' Quellen anzeigen</button>';
    html += '<div class="chat-sources-list" id="' + listId + '">';
    sources.forEach(function(s) {
      var pct = Math.round((s.similarity_score || 0) * 100);
      var wikiUrl = '/wiki/' + encodeURIComponent((s.page_title || '').replace(/ /g, '_'));
      html += '<div class="chat-source-item">'
        + '<h5><a href="' + wikiUrl + '">' + escapeHtml(s.page_title || '') + '</a></h5>'
        + '<p class="chat-source-snippet">' + escapeHtml(truncate(s.content_text || '', 150)) + '</p>'
        + '<div class="chat-source-meta">Relevanz: ' + pct + '% · ' + escapeHtml(s.source || '') + '</div>'
        + '</div>';
    });
    html += '</div>';
    sourcesPanel.innerHTML = html;
  }
 
  function setLoading(loading) {
    isLoading = loading;
    input.disabled = loading;
    sendBtn.disabled = loading;
    if (loading) {
      addLoadingIndicator();
    } else {
      removeLoadingIndicator();
    }
   }
   }


   .perplexity-search input[type="text"] {
   function updateStatus(remaining) {
     width: 300px;
    if (remaining > 0) {
      statusEl.textContent = remaining + ' R\u00fcckfrage' + (remaining !== 1 ? 'n' : '') + ' verbleibend';
    } else if (remaining === 0) { if (conversationId) {
      statusEl.textContent = 'Keine R\u00fcckfragen mehr m\u00f6glich';
      input.disabled = true;
      sendBtn.disabled = true;
      input.placeholder = 'Starte eine neue Unterhaltung';
    } }
     newBtn.className = conversationId ? 'visible' : '';
   }
   }


   .perplexity-search input[type="submit"] {
   function resetConversation() {
     padding: 0px 20px;
    conversationId = null;
     background-color: #4CAF50;
    messagesEl.innerHTML = '';
     color: white;
    sourcesPanel.className = '';
     border: none;
    sourcesPanel.innerHTML = '';
     border-radius: 3px;
    statusEl.textContent = '';
     newBtn.className = '';
     input.disabled = false;
     sendBtn.disabled = false;
     input.placeholder = 'Stelle eine Frage \u00fcber M\u00fcnster \u2026';
     input.focus();
   }
   }
  newBtn.addEventListener('click', resetConversation);
  form.addEventListener('submit', function(e) {
    e.preventDefault();
    if (isLoading) return;
    var message = input.value.trim();
    if (!message) return;
    input.value = '';
    addUserMessage(message);
    setLoading(true);
    var body = { message: message };
    if (conversationId) {
      body.conversation_id = conversationId;
    }
    var url = location.protocol + '//' + apiHost + '/chat';
    fetch(url, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(body)
    })
      .then(function(res) {
        if (!res.ok) {
          return res.json().then(function(data) {
            throw new Error(data.detail || 'HTTP ' + res.status);
          });
        }
        return res.json();
      })
      .then(function(data) {
        setLoading(false);
        conversationId = data.conversation_id;
        addAssistantMessage(data.answer);
        renderSources(data.sources);
        updateStatus(data.remaining_followups);
        input.focus();
      })
      .catch(function(err) {
        setLoading(false);
        addError('Fehler: ' + err.message);
        input.focus();
      });
  });
})();
</script>
<style type="text/css">


.overlay-container {
.overlay-container {
Zeile 61: Zeile 453:


</style>
</style>
<div class="overlay-container">
  <div class="overlay-content">
    <p class="headline-text">Wonach suchst du?</p>
      <div class="perplexity-search">
        <form onsubmit="window.open('https://www.perplexity.ai/?q=' + encodeURIComponent(this.query.value), '_blank'); return false;">
        <input type="text" name="query" placeholder="z. B. Wie melde ich mich um?">
        <input type="submit" value="Suche">
        </form>
      </div>
    <p>Unser Münster Wiki und Informationen aus den öffentlichen Seiten in Münster stehen dir hier zur Verfügung. Beachte: KI-Suche kann Fehler enthalten. Bitte prüfe die Ergebnisse. Personenbezogenen Daten können zur Optimierung der KI genutzt werden </p>
  </div>
</div>


</includeonly>
</includeonly>

Version vom 28. April 2026, 08:52 Uhr