Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
XHXIAIEIN committed Jun 5, 2024
1 parent 2b10f0a commit 13846c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<body>
<h1>相册截图工具</h1>
<div id="dropArea">点击此处,导入文件夹</div>
<input type="file" id="fileInput" webkitdirectory multiple>
<input type="file" id="fileInput" accept="image/*" webkitdirectory multiple>

<div id="configPanel">
<div class="configGroup">
Expand Down
32 changes: 4 additions & 28 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ document.addEventListener('DOMContentLoaded', () => {

}

async function handleFiles(files, { photoWall, sortOrder, progressContainer, progressBar, progressText, captureButton }) {
async function handleFiles(files, UIElements) {
const { photoWall, sortOrder, progressContainer, progressBar, progressText, captureButton } = UIElements
photoWall.innerHTML = '';
photoWallContainer.style.display = 'none';

Expand Down Expand Up @@ -101,9 +102,9 @@ document.addEventListener('DOMContentLoaded', () => {
return files.sort((a, b) => {
switch (order) {
case 'nameAsc':
return fileNameCompare(a.name, b.name);
return a.localeCompare(b);
case 'nameDesc':
return fileNameCompare(b.name, a.name);
return b.localeCompare(a);
case 'dateAsc':
return a.lastModified - b.lastModified;
case 'dateDesc':
Expand All @@ -122,30 +123,6 @@ document.addEventListener('DOMContentLoaded', () => {
});
}

function fileNameCompare(a, b) {
if (a == null || b == null) return 0;
let na = a.split(/[-_., (]/);
let nb = b.split(/[-_., (]/);
let maxLoop = Math.max(na.length, nb.length);
for (let i = 0; i < maxLoop; i++) {
if (!isNaN(Number(na[i])) && !isNaN(Number(nb[i]))) {
let num = Number(na[i]) - Number(nb[i]);
if (num !== 0) {
return num;
}
}
}
let ma = a.match(/[0-9]+/);
let mb = b.match(/[0-9]+/);
if (ma && mb && ma.length && mb.length) {
let num = Number(ma[0]) - Number(mb[0]);
if (num !== 0) {
return num;
}
}
return a.localeCompare(b);
}

function loadImage(file, photoWall) {
return new Promise((resolve) => {
const img = document.createElement('img');
Expand Down Expand Up @@ -221,7 +198,6 @@ document.addEventListener('DOMContentLoaded', () => {
currentPhotos.forEach(photo => {
const clone = photo.cloneNode(true);
clone.style.padding = `${capturePaddingYInput.value}px ${capturePaddingXInput.value}px`;
clone.style.boxSizing = 'border-box';
clone.style.justifyItems = 'center';
clone.style.alignItems = 'center';
fragment.appendChild(clone);
Expand Down

0 comments on commit 13846c9

Please sign in to comment.