Widget:StartseitenSuche: Unterschied zwischen den Versionen

Aus MediaWiki
Wechseln zu:Navigation, Suche
Keine Bearbeitungszusammenfassung
KKeine Bearbeitungszusammenfassung
 
(24 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
<includeonly>
<includeonly>
<style type="text/css">
<div class="overlay-container">
   .perplexity-search {
   <div class="overlay-content">
     display: inline-block;
     <div id="chat-widget">
    padding: 10px;
      <div id="chat-messages"></div>
    background-color: #f0f0f0;
      <div id="chat-sources-panel"></div>
    border-radius: 5px;
      <form id="chat-form">
     width: max-content;
        <input type="text" id="chat-input" placeholder="Stelle mir deine Frage …" autocomplete="off" />
   }
        <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>
   </div>
</div>


  .perplexity-search input[type="text"] {
<style>
    width: 200px;
.overlay-container {
    padding: 5px;
  position: relative;
    border: 1px solid #ccc;
  width: 100%;
    border-radius: 3px;
  min-height: 400px;
    display: block;
  padding: 24px;
   }
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 12px;
  background-color: #2f3e46;
  background-image: url("/w/images/a/a9/Schloss-Muenster-Philipp-Foelting-CC-BY-SA.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
   box-sizing: border-box;
}


  .perplexity-search input[type="submit"] {
.overlay-container::before {
    padding: 5px 10px;
  content: "";
    background-color: #4CAF50;
  position: absolute;
    color: white;
  inset: 0;
    border: none;
  background: rgba(0, 0, 0, 0.38);
    border-radius: 3px;
  z-index: 1;
    cursor: pointer;
}
    width: auto;
    margin-top: 10px;
    float: right;
  }


.overlay-container {
.overlay-content {
   position: relative;
   position: relative;
  z-index: 2;
   width: 100%;
   width: 100%;
  max-width: 860px;
  padding: 0px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-sizing: border-box;
}
#chat-widget {
  width: 80%;
  margin: 0 auto;
  font-family: -apple-system, "system-ui", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #212529;
  display: flex;
  flex-direction: column;
  background: transparent;
}
#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 Web-Inhalten für Münster. Beachte: KI-Suche kann Fehler machen. Prüfe deine Ergebnisse sorgfältig. Verwende keine personenbezogenen Daten.";
  display: block;
  text-align: center;
  color: #666;
  font-size: 14px;
  padding: 20px 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;
   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;
}
}


.overlay-container img {
.chat-source-item .chat-source-meta {
   width: 100%; /* Passt das Bild an die Containergröße an */
   font-size: 11px;
  color: #999;
  margin-top: 3px;
}
}


.overlay-content {
#chat-form {
   position: absolute;
   display: flex;
   top: 50%; /* Position des Widgets */
   margin-top: 8px;
   left: 50%;
}
   transform: translate(-50%, -50%);
 
   color: white; /* Textfarbe: Weiß */
#chat-input {
   background-color: #00308D; /* Hintergrundfarbe: Blau */
   flex: 1;
   border-radius: 15px; /* Abgerundete Ecken */
   padding: 10px 14px;
   padding: 20px;
  font-size: 15px;
   text-align: center;
   border: 1px solid #ccc;
   width: 80%; /* Breite des Widgets, kannst du anpassen */
   border-right: none;
   border-radius: 4px 0 0 4px;
   outline: none;
   transition: border-color 0.2s;
  color: #212529;
  background: #fff;
   min-width: 0;
}
}


.overlay-content p {
#chat-input:focus {
   margin: 10px 0; /* Abstand zwischen den Textabsätzen */
   border-color: #4CAF50;
}
}


.overlay-content input[type="text"] {
#chat-input:disabled {
   width: 100%; /* Suchleiste wird die volle Breite des Containers einnehmen */
   background: #f5f5f5;
  padding: 10px;
   color: #999;
   border: none;
  border-radius: 5px;
  margin-bottom: 10px;
}
}


.overlay-content input[type="submit"] {
#chat-send {
   padding: 10px 20px;
   padding: 10px 20px;
   background-color: white;
  font-size: 15px;
   color: #007bff;
  font-weight: 500;
  cursor: pointer;
   background: #4CAF50;
   color: #fff;
   border: none;
   border: none;
   border-radius: 5px;
   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;
  gap: 12px;
  margin-top: 8px;
  min-height: 28px;
}
 
#chat-status {
  font-size: 12px;
  color: #666;
}
 
#chat-new {
  display: none;
  background: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 4px 12px;
  font-size: 12px;
  color: #555;
   cursor: pointer;
   cursor: pointer;
  transition: background 0.15s;
}
}


.overlay-content input[type="submit"]:hover {
#chat-new:hover {
   background-color: #0056b3; /* Hover-Effekt für den Suchbutton */
   background: #f5f5f5;
  color: white;
}
}


.overlay-content .headline-text {
#chat-new.visible {
   font-size: 1.5em; /* Größerer Schriftzug */
   display: inline-block;
  font-weight: bold; /* Dickere Schrift */
  margin: 10px 0;
}
}


/* To make images responsive */
.chat-msg-error {
.img-fluid img {
  align-self: center;
max-width:100%;
  background: #fef2f2;
height:auto;
  color: #b00;
  border: 1px solid #fca5a5;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 6px;
}
 
/* Tablet */
@media (max-width: 900px) {
  .overlay-container {
    min-height: 340px;
    padding: 18px;
    border-radius: 10px;
  }
 
  .overlay-content {
    padding: 16px;
    border-radius: 10px;
  }
}
 
/* Smartphone */
@media (max-width: 600px) {
  .overlay-container {
    min-height: 280px;
    padding: 12px;
    align-items: stretch;
    border-radius: 8px;
  }
 
  .overlay-content {
    padding: 14px;
    border-radius: 8px;
  }
 
  #chat-form {
    flex-direction: column;
    gap: 8px;
  }
 
  #chat-input {
    border-right: 1px solid #ccc;
    border-radius: 4px;
  }
 
  #chat-send {
    width: 100%;
    border-radius: 4px;
  }
 
  .chat-msg {
    max-width: 100%;
  }
 
  #chat-footer {
    flex-direction: column;
    align-items: flex-start;
  }
}
}


/* Kleine Smartphones */
@media (max-width: 400px) {
  .overlay-container {
    min-height: 240px;
    padding: 10px;
  }
  .overlay-content {
    padding: 12px;
  }
  #chat-messages {
    max-height: 420px;
  }
  .chat-msg {
    font-size: 14px;
    padding: 9px 12px;
  }
}
</style>
</style>


<div class="overlay-container">
<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();
    }
  }
 
  function updateStatus(remaining) {
    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' : '';
  }
 
  function resetConversation() {
    conversationId = null;
    messagesEl.innerHTML = '';
    sourcesPanel.className = '';
    sourcesPanel.innerHTML = '';
    statusEl.textContent = '';
    newBtn.className = '';
    input.disabled = false;
    sendBtn.disabled = false;
    input.placeholder = 'Stelle eine Frage \\u00fcber M\\u00fcnster \\u2026';
    input.focus();
  }


   [[File:Startseitenfoto.jpg|class=img-fluid|width=100%|link=]]
   newBtn.addEventListener('click', resetConversation);


   <div class="overlay-content">
   form.addEventListener('submit', function(e) {
     <p class="headline-text">Wonach suchst du?</p>
    e.preventDefault();
    if (isLoading) return;
    var message = input.value.trim();
     if (!message) return;


      <div class="perplexity-search">
    input.value = '';
        <form onsubmit="window.open('https://www.perplexity.ai/?q=' + encodeURIComponent(this.query.value), '_blank'); return false;">
    addUserMessage(message);
        <input type="text" name="query" placeholder="z. B. Wie melde ich mich um?">
    setLoading(true);
        <input type="submit" value="Suche">
        </form>
      </div>


     <p>Unser Münster Wiki und alle weitere Informationen aus den öffentlichen Seiten der Stadt Münster stehen dir hier zur Verfügung</p>
     var body = { message: message };
  </div>
    if (conversationId) {
</div>
      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>
</includeonly>
</includeonly>

Aktuelle Version vom 5. Mai 2026, 19:54 Uhr