Wiki source code of LLMChatRenderer
Hide last authors
author | version | line-number | content |
---|---|---|---|
![]() |
11.1 | 1 | {{html}} |
2 | <script> | ||
![]() |
13.1 | 3 | console.log("✅ Script running without Velocity"); |
![]() |
11.1 | 4 | |
5 | document.addEventListener('DOMContentLoaded', function () { | ||
6 | function processAssistantMessages() { | ||
7 | const messages = document.querySelectorAll('.assistantMessage'); | ||
8 | messages.forEach(msg => { | ||
9 | const html = msg.innerHTML; | ||
10 | const chunkMap = {}; | ||
![]() |
13.1 | 11 | const chunkRegex = /\[(\d+)\]\s*\((https:\/\/[^)]+)\)/g; |
![]() |
11.1 | 12 | let match; |
13 | while ((match = chunkRegex.exec(html)) !== null) { | ||
14 | const index = match[1]; | ||
15 | const url = match[2]; | ||
16 | const path = extractDownloadPath(url); | ||
17 | if (path) chunkMap[index] = path; | ||
18 | } | ||
19 | |||
20 | let currentIndex = null; | ||
![]() |
13.1 | 21 | const processed = html.replace(/(\[\d+\])\s*\((https:\/\/[^)]+)\)/g, (full, idx) => { |
22 | currentIndex = idx.replace(/\D/g, ''); | ||
![]() |
11.1 | 23 | return full; |
![]() |
13.1 | 24 | }).replace(/\[\[(image|doc_)?([^\]]+?)\]\]/g, function (_, type, filename) { |
![]() |
11.1 | 25 | if (!currentIndex || !chunkMap[currentIndex]) return ''; |
26 | const path = chunkMap[currentIndex]; | ||
27 | const downloadURL = `/bin/download/${path}/${filename}`; | ||
![]() |
13.1 | 28 | return type === 'image' |
29 | ? `<img src="${downloadURL}" style="max-width:300px; display:block; margin:1em 0;" />` | ||
30 | : `<a href="${downloadURL}" target="_blank">📄 Download ${filename}</a>`; | ||
![]() |
11.1 | 31 | }); |
32 | |||
33 | msg.innerHTML = processed; | ||
34 | }); | ||
35 | } | ||
36 | |||
37 | function extractDownloadPath(viewURL) { | ||
![]() |
13.1 | 38 | const match = viewURL.match(/\/bin\/view\/([^?#]+)/); |
39 | return match ? decodeURIComponent(match[1]) : null; | ||
![]() |
11.1 | 40 | } |
41 | |||
42 | const observer = new MutationObserver(processAssistantMessages); | ||
43 | observer.observe(document.body, { childList: true, subtree: true }); | ||
44 | }); | ||
45 | </script> | ||
46 | {{/html}} | ||
47 |