-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfavorites.plugin.js
87 lines (71 loc) · 2.8 KB
/
favorites.plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/***
*
* 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: '<span class="favorites-label" style="background-color:transparent;background: rgba(0,0,0,0.5)">'
+suLabel+':</span>', type: 'label'},
{ html: '<i class="fa-regular fa-heart"></i>', on_click: onFavoritesClick, filter: onFavoritesClickFilter },
{ html: '<i class="fa-regular fa-floppy-disk"></i>', 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;
}
})();