feat(custom text): add text file opening (Shuja-Mahmood) (#4596)

This commit is contained in:
Shuja-Mahmood 2023-09-11 22:22:39 +05:00 committed by GitHub
parent 9f05da905a
commit 7c971e5d84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 1 deletions

View file

@ -90,7 +90,7 @@
.buttonsTop {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 1rem;
}

View file

@ -63,6 +63,9 @@
// .pageSettings .section.themes .buttons {
// grid-template-columns: 1fr 1fr 1fr;
// }
#customTextPopupWrapper #customTextPopup .buttonsTop {
grid-template-columns: 1fr 1fr;
}
}
//1050px

View file

@ -384,4 +384,30 @@ $(`#customTextPopupWrapper .longCustomTextWarning .button`).on("click", () => {
$(`#customTextPopup .longCustomTextWarning`).addClass("hidden");
});
$(`#fileInput`).on("change", () => {
const file = ($(`#fileInput`)[0] as HTMLInputElement).files?.[0];
if (file) {
if (file.type !== "text/plain") {
Notifications.add("File is not a text file", -1, {
duration: 5,
});
return;
}
const reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = (readerEvent): void => {
const content = readerEvent.target?.result as string;
$(`${popup} textarea`).val(content);
$(`#fileInput`).val("");
};
reader.onerror = (): void => {
Notifications.add("Failed to read file", -1, {
duration: 5,
});
};
}
});
Skeleton.save(skeletonId);

View file

@ -435,6 +435,11 @@
<i class="fas fa-folder"></i>
Show saved texts
</div>
<input id="fileInput" type="file" class="hidden" accept=".txt" />
<label for="fileInput" class="button importText">
<i class="fas fa-file-import"></i>
Open file
</label>
<div class="button wordfilter">
<i class="fas fa-filter"></i>
Words filter