... |
... |
@@ -1,19 +4,14 @@ |
1 |
|
-{{velocity}} |
2 |
|
-#if ($xcontext.action != 'jsx') |
3 |
|
-$xwiki.parseContent(" |
4 |
4 |
{{html}} |
5 |
5 |
<script> |
6 |
|
-console.log('✅ Renderer script is running'); |
|
3 |
+console.log("✅ Script running without Velocity"); |
7 |
7 |
|
8 |
8 |
document.addEventListener('DOMContentLoaded', function () { |
9 |
9 |
function processAssistantMessages() { |
10 |
10 |
const messages = document.querySelectorAll('.assistantMessage'); |
11 |
|
- |
12 |
12 |
messages.forEach(msg => { |
13 |
13 |
const html = msg.innerHTML; |
14 |
|
- |
15 |
15 |
const chunkMap = {}; |
16 |
|
- const chunkRegex = /\\[(\\d+)\\]\\s*\\((https:\\/\\/[^)]+)\\)/g; |
|
11 |
+ const chunkRegex = /\[(\d+)\]\s*\((https:\/\/[^)]+)\)/g; |
17 |
17 |
let match; |
18 |
18 |
while ((match = chunkRegex.exec(html)) !== null) { |
19 |
19 |
const index = match[1]; |
... |
... |
@@ -23,19 +23,16 @@ |
23 |
23 |
} |
24 |
24 |
|
25 |
25 |
let currentIndex = null; |
26 |
|
- const processed = html.replace(/(\\[\\d+\\])\\s*\\((https:\\/\\/[^)]+)\\)/g, (full, idx) => { |
27 |
|
- currentIndex = idx.replace(/\\D/g, ''); |
|
21 |
+ const processed = html.replace(/(\[\d+\])\s*\((https:\/\/[^)]+)\)/g, (full, idx) => { |
|
22 |
+ currentIndex = idx.replace(/\D/g, ''); |
28 |
28 |
return full; |
29 |
|
- }).replace(/\\[\\[(image|doc_)?([^\\]]+?)\\]\\]/g, function (_, type, filename) { |
|
24 |
+ }).replace(/\[\[(image|doc_)?([^\]]+?)\]\]/g, function (_, type, filename) { |
30 |
30 |
if (!currentIndex || !chunkMap[currentIndex]) return ''; |
31 |
31 |
const path = chunkMap[currentIndex]; |
32 |
32 |
const downloadURL = `/bin/download/${path}/${filename}`; |
33 |
|
- |
34 |
|
- if (type === 'image') { |
35 |
|
- return `<img src='\${downloadURL}' style='max-width:300px; display:block; margin:1em 0;' />`; |
36 |
|
- } else { |
37 |
|
- return `<a href='\${downloadURL}' target='_blank'>📄 Download \${filename}</a>`; |
38 |
|
- } |
|
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>`; |
39 |
39 |
}); |
40 |
40 |
|
41 |
41 |
msg.innerHTML = processed; |
... |
... |
@@ -43,9 +43,8 @@ |
43 |
43 |
} |
44 |
44 |
|
45 |
45 |
function extractDownloadPath(viewURL) { |
46 |
|
- const match = viewURL.match(/\\/bin\\/view\\/([^?#]+)/); |
47 |
|
- if (!match) return null; |
48 |
|
- return decodeURIComponent(match[1]); |
|
38 |
+ const match = viewURL.match(/\/bin\/view\/([^?#]+)/); |
|
39 |
+ return match ? decodeURIComponent(match[1]) : null; |
49 |
49 |
} |
50 |
50 |
|
51 |
51 |
const observer = new MutationObserver(processAssistantMessages); |
... |
... |
@@ -53,7 +53,4 @@ |
53 |
53 |
}); |
54 |
54 |
</script> |
55 |
55 |
{{/html}} |
56 |
|
-") |
57 |
|
-#end |
58 |
|
-{{/velocity}} |
59 |
59 |
|