Compare commits

...

4 Commits

Author SHA1 Message Date
767048d79b Merge pull request 'Improved video handling in reply' (#73) from BordedDev/snek:bugfix/video-handling-in-reply into main
Reviewed-on: retoor/snek#73
Reviewed-by: retoor <retoor@noreply@molodetz.nl>
2025-10-04 19:05:23 +02:00
13181fa275 Merge pull request 'Fixed upload handling' (#72) from BordedDev/snek:bugfix/upload-handling into main
Reviewed-on: retoor/snek#72
Reviewed-by: retoor <retoor@noreply@molodetz.nl>
2025-10-04 19:01:54 +02:00
BordedDev
37e872809b Improved video handling in quote 2025-10-04 16:39:00 +02:00
BordedDev
b99339ea93 Fixed upload handling 2025-10-04 16:30:54 +02:00
2 changed files with 55 additions and 21 deletions

View File

@ -34,6 +34,12 @@ export class ReplyEvent extends Event {
img.replaceWith(document.createTextNode(src));
});
// Replace <video> with just their src
newMessage.querySelectorAll('video').forEach(vid => {
const src = vid.src || vid.currentSrc || vid.querySelector('source').src;
vid.replaceWith(document.createTextNode(src));
});
// Replace <iframe> with their src
newMessage.querySelectorAll('iframe').forEach(iframe => {
const src = iframe.src || iframe.currentSrc;

View File

@ -101,19 +101,40 @@ setInterval(() => requestIdleCallback(updateTimes), 30000);
const textBox = chatInputField.textarea;
textBox.addEventListener("paste", async (e) => {
try {
const clipboardItems = await navigator.clipboard.read();
const dt = new DataTransfer();
e.preventDefault();
const uploadButton = chatInputField.fileUploadGrid;
const clipboardItems = await navigator.clipboard.read()
for (const item of clipboardItems) {
if (item.types.every(v => v === "text/plain")) {
const text = await (await item.getType("text/plain")).text();
chatInputField.value += text;
continue
}
if (item.types.every(t => t.startsWith('text/'))) {
console.log("All types are text:", item.types);
const codeType = item.types.find(t => !t.startsWith('text/plain') && !t.startsWith('text/html'));
let code = await(await item.getType(codeType ?? 'text/plain')).text();
const minIndentDepth = code.split('\n').reduce((acc, line) => {
if (!line.trim()) return acc;
const match = line.match(/^(\s*)/);
return match ? Math.min(acc, match[1].length) : acc;
}, 9000)
code = code.split('\n').map(line => line.slice(minIndentDepth)).join('\n')
chatInputField.value += `\`\`\`${codeType?.split('/')?.[1] ?? ''}\n${code}\n\`\`\`\n`;
} else {
for (const type of item.types.filter(t => !t.startsWith('text/'))) {
const blob = await item.getType(type);
dt.items.add(new File([blob], "image.png", { type }));
const name = type.replace('/', '.')
uploadButton.uploadsStarted++
uploadButton.createTile(new File([blob], name, {type}))
}
}
if (dt.items.length > 0) {
const uploadButton = chatInputField.uploadButton;
const input = uploadButton.shadowRoot.querySelector('.file-input');
input.files = dt.files;
await uploadButton.uploadFiles();
}
} catch (error) {
console.error("Failed to read clipboard contents: ", error);
@ -123,10 +144,17 @@ chatArea.addEventListener("drop", async (e) => {
e.preventDefault();
const dt = e.dataTransfer;
if (dt.items.length > 0) {
const uploadButton = chatInputField.uploadButton;
const input = uploadButton.shadowRoot.querySelector('.file-input');
input.files = dt.files;
await uploadButton.uploadFiles();
const uploadButton = chatInputField.fileUploadGrid;
for (const item of dt.items) {
if (item.kind === "file") {
const file = item.getAsFile();
if (file) {
uploadButton.uploadsStarted++
uploadButton.createTile(file)
}
}
}
}
});
chatArea.addEventListener("dragover", e => {