Skip to content

Commit

Permalink
Update content.js
Browse files Browse the repository at this point in the history
- Fixed renaming 'image.png' to 'CnP_{datetime}.{file.tpe}'
- Use 24 hours format instead
  • Loading branch information
kazcfz committed Sep 24, 2024
1 parent 30acec1 commit ccd3453
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ function previewImage(webCopiedImgSrc, readerEvent, blob) {
badge.title += fileName + '\n';
badge.innerText = parseInt(badge.innerText) + 1;

if (fileName == 'image.png' || !blob.name)
fileName = 'CnP_'+new Date().toLocaleString().replace(/, /g, '_').replace(/[\/: ]/g, '')+'.'+blob.type.split('/').pop();

if (!imagePreview) {
// Preview image types
if (blob.type.split('/')[0] == 'image') {
Expand Down Expand Up @@ -355,7 +352,10 @@ function handleFileInputClick(event) {

// Array of promises to process each file
const readPromises = Array.from(dataTransfer.files).map(file => {
fileList.items.add(new File([file], file.name, { type: file.type }));
let filename = file.name;
if (!filename || filename == 'image.png')
filename = 'CnP_'+new Date().toLocaleString('en-US', {hour12: false}).replace(/, /g, '_').replace(/[\/: ]/g, '')+'.'+file.type.split('/').pop();
fileList.items.add(new File([file], filename, { type: file.type }));
return readFileAsDataURL(file);
});
await Promise.all(readPromises);
Expand Down

0 comments on commit ccd3453

Please sign in to comment.