/*** * * Favorites Plugin for Easy Diffusion * v.0.9.1, last updated: 1/26/2024 * By Gary W. * * This plugin allows you to tag your favorite images, by saving the seeds to a file. * This file can then be used externally to assist with finding and copying just those * images out of what is often a working folder with many unnecessary intermediate files. * * See separate utility to automatically move a batch of images. * * * Free to use with the CMDR2 Stable Diffusion UI. * */ (function() { "use strict" const favorites_loadDate = Date.now(); //load date as soon as possible, to closely match the folder date const suLabel = 'Favorites'; //base label prefix PLUGINS['IMAGE_INFO_BUTTONS'].push([ { html: '' +suLabel+':', type: 'label'}, { html: '', on_click: onFavoritesClick, filter: onFavoritesClickFilter }, { html: '', on_click: onFavoritesSaveClick, filter: onFavoritesSaveClickFilter } ]) var names ="List of selected Favorites (seeds)\n"; function onFavoritesClick(origRequest, image) { //const name = getDownloadFilename(image, origRequest["output_format"]) //names=name+'\t'+convertDateToStr(1705429635772)+'\n'; //toggle the icon let unselected= this.children[0].classList.replace('fa-regular','fa-solid') //if we already selected, don't save the seed again if (unselected) { //if seed is already present, no need to add it again if (names.search('\n'+image.dataset["seed"]+'\n')<0) { names=names+image.dataset["seed"]+'\n'; } } else { //remove from the list, with an untoggle this.children[0].classList.replace('fa-solid','fa-regular'); // \n is used as a delimiter on both sides, to ensure that there are no false matches due to length. names = names.replace('\n'+image.dataset["seed"]+'\n', '\n'); } } //Save text file with list of seeds function onFavoritesSaveClick(origRequest, image) { // Create a blob from the text var blob = new Blob([names], {type: "text/plain;charset=utf-8"}); // Create a temporary URL for the blob var url = URL.createObjectURL(blob); // Create an anchor element with the download attribute var a = document.createElement("a"); a.href = url; a.download = "favoriteslist-"+favorites_loadDate+".txt"; // Append the anchor to the document body document.body.appendChild(a); // Trigger a click event on the anchor a.click(); // Remove the anchor from the document body document.body.removeChild(a); // Revoke the temporary URL URL.revokeObjectURL(url); } function onFavoritesClickFilter(origRequest, image) { return true; } function onFavoritesSaveClickFilter(origRequest, image) { return true; } })();