updated filename

This commit is contained in:
caranicas 2022-09-03 11:06:34 -04:00
parent d52b973b44
commit 6b65b05e2f

View File

@ -587,7 +587,7 @@ async function doMakeImage(reqBody) {
imgSaveBtn.addEventListener('click', function() { imgSaveBtn.addEventListener('click', function() {
let imgDownload = document.createElement('a') let imgDownload = document.createElement('a')
imgDownload.download = generateUUID() + '.png' imgDownload.download = createFileName();
imgDownload.href = imgBody imgDownload.href = imgBody
imgDownload.click() imgDownload.click()
}) })
@ -692,22 +692,42 @@ async function makeImage() {
} }
} }
function generateUUID() { // Public Domain/MIT // create a file name with embedded prompt and metadata
var d = new Date().getTime();//Timestamp // for easier cateloging and comparison
var d2 = ((typeof performance !== 'undefined') && performance.now && (performance.now()*1000)) || 0;//Time in microseconds since page-load or 0 if unsupported function createFileName() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16;//random number between 0 and 16 // Most important information is the prompt
if(d > 0){//Use timestamp until depleted const underscoreName = promptField.value = promptField.value.replace(/[^a-zA-Z0-9]/g, '_');
r = (d + r)%16 | 0; const seed = seedField.value;
d = Math.floor(d/16); const steps = numInferenceStepsField.value;
} else {//Use microseconds since page-load if supported const guidance = guidanceScaleField.value;
r = (d2 + r)%16 | 0;
d2 = Math.floor(d2/16); // name and the top level metadata
} let fileName = `sd_${underscoreName}_Seed:${seed}_Steps:${steps}_Guidance:${guidance}`;
return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
}); // add the tags
let tags = [];
let tagString = '';
document.querySelectorAll(modifyTagsSelector).forEach(function(tag) {
tags.push(tag.innerHTML);
})
// join the tags with a pipe
if (tags.length > 0) {
tagString = '_Tags:';
tagString += tags.join('|');
}
// append empty or populated tags
fileName += `${tagString}`;
// add the file extension
fileName += `.png`;
return fileName;
} }
soundToggle.addEventListener('click', handleBoolSettingChange(SOUND_ENABLED_KEY)) soundToggle.addEventListener('click', handleBoolSettingChange(SOUND_ENABLED_KEY))
soundToggle.checked = isSoundEnabled() soundToggle.checked = isSoundEnabled()