put code into functions
This commit is contained in:
parent
79eb3e91ac
commit
58895aa6fe
3 changed files with 55 additions and 27 deletions
|
|
@ -1128,17 +1128,37 @@ document.getElementById("save-area-file").addEventListener("change", (event) =>
|
|||
var label = document.getElementById("save-area-file").nextElementSibling;
|
||||
var labelInitialText = label.innerHTML;
|
||||
|
||||
var fileName = event.target.files[0].name;
|
||||
/* Shorten the file name if longer than 16 characters. Display first 10 characters and last 4. */
|
||||
var fileName = FileNameFormat(event.target.files[0], 16, 10, 4);
|
||||
|
||||
/* Display a custom formatted last modified date. */
|
||||
var fileDate = FileDateFormat(event.target.files[0]);
|
||||
|
||||
if (fileName) {
|
||||
label.innerHTML = `${SYMBOL_FILE}${fileName} ${fileDate}`;
|
||||
} else {
|
||||
label.innerHTML = labelInitialText;
|
||||
}
|
||||
});
|
||||
|
||||
function FileNameFormat(file, nameLength, beginLength, endLength) {
|
||||
|
||||
var fileName = file.name;
|
||||
|
||||
/* Shorten the file name if too long */
|
||||
if (fileName.length > 16) {
|
||||
if (fileName.length > nameLength) {
|
||||
|
||||
let begin = fileName.slice(0, 10); // take 10 characters from the beginning (0)
|
||||
let end = fileName.slice(-4); // take 4 characters from the end (-)
|
||||
let begin = fileName.slice(0, beginLength); // take X characters from the beginning (0)
|
||||
let end = fileName.slice(-endLength); // take X characters from the end (-)
|
||||
fileName = `${begin}..${end}`;
|
||||
}
|
||||
|
||||
var fileDate = new Date(event.target.files[0].lastModified);
|
||||
return fileName;
|
||||
}
|
||||
|
||||
function FileDateFormat(file) {
|
||||
|
||||
var fileDate = new Date(file.lastModified);
|
||||
|
||||
var year = fileDate.getFullYear();
|
||||
var month = fileDate.getMonth() + 1;
|
||||
|
|
@ -1153,14 +1173,8 @@ document.getElementById("save-area-file").addEventListener("change", (event) =>
|
|||
if (minutes < 10) minutes = "0" + minutes;
|
||||
if (seconds < 10) seconds = "0" + seconds;
|
||||
|
||||
var fileDateFormat = `${year}.${month}.${day} ${hour}:${minutes}:${seconds}`;
|
||||
|
||||
if (fileName) {
|
||||
label.innerHTML = `${SYMBOL_FILE}${fileName} ${fileDateFormat}`;
|
||||
} else {
|
||||
label.innerHTML = labelInitialText;
|
||||
}
|
||||
});
|
||||
return `${year}.${month}.${day} ${hour}:${minutes}:${seconds}`;
|
||||
}
|
||||
|
||||
/* -------- Clean the text area and file input from leftover save file if present (Firefox especially) -------- */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue