1
0
mirror of https://github.com/coalaura/whiskr.git synced 2025-12-02 20:22:52 +00:00

fix saving not working & better language detection

This commit is contained in:
Laura
2025-11-04 00:46:24 +01:00
parent ac389ddf94
commit 468f7c04c9
4 changed files with 153 additions and 36 deletions

View File

@@ -883,6 +883,7 @@ body:not(.loading) #loading {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
cursor: pointer;
}
.files .file::before {

View File

@@ -549,38 +549,7 @@
return;
}
// build form
const form = make("form");
form.style.display = "none";
form.enctype = "multipart/form-data";
form.method = "post";
form.action = "/-/preview";
form.target = "_blank";
// add name field
const name = make("input");
name.name = "name";
name.value = file.name;
form.appendChild(name);
// add content field
const content = make("textarea");
content.name = "content";
content.value = file.content;
form.appendChild(content);
// send form
document.body.appendChild(form);
form.submit();
form.remove();
previewFile(file);
}
#handleImages(element) {
@@ -1756,6 +1725,18 @@
_file.appendChild(_name);
_name.addEventListener("click", () => {
previewFile(file);
});
_name.addEventListener("auxclick", event => {
if (event.button !== 1) {
return;
}
previewFile(file);
});
// token count
if ("tokens" in file && Number.isInteger(file.tokens)) {
const _tokens = make("div", "tokens");

View File

@@ -176,6 +176,41 @@ function lines(text) {
return count + 1;
}
function previewFile(file) {
// build form
const form = make("form");
form.style.display = "none";
form.enctype = "multipart/form-data";
form.method = "post";
form.action = "/-/preview";
form.target = "_blank";
// add name field
const name = make("input");
name.name = "name";
name.value = file.name;
form.appendChild(name);
// add content field
const content = make("textarea");
content.name = "content";
content.value = file.content;
form.appendChild(content);
// send form
document.body.appendChild(form);
form.submit();
form.remove();
}
function readFile(file, handler, onError = false) {
return new Promise(resolve => {
const reader = new FileReader();