refactored new image handling for image feed; created addImageToFeed

This commit is contained in:
cho
2024-03-10 05:18:23 -07:00
parent e147bbab3a
commit c632d01d38
+32 -26
View File
@@ -341,6 +341,27 @@ app.registerExtension({
columnInput.value = v;
}
function addImageToFeed(href) {
const method = feedDirection.value === "newest first" ? "prepend" : "append";
imageList[method](
$el("div", [
$el(
"a",
{
target: "_blank",
href,
onclick: (e) => {
const imgs = [...imageList.querySelectorAll("img")].map((img) => img.getAttribute("src"));
lightbox.show(imgs, imgs.indexOf(href));
e.preventDefault();
},
},
[$el("img", { src: href })]
),
])
);
}
imageFeed.append(
$el("div.pysssss-image-feed-menu", [
$el("section.sizing-menu", {}, [
@@ -424,36 +445,21 @@ app.registerExtension({
}
for (const src of detail.output.images) {
if (deduplicateFeed.value) {
// deduplicate the feed by ignoring images with the same filename/type/subfolder
const fingerprint = JSON.stringify({filename: src.filename, type: src.type, subfolder: src.subfolder});
if (seenImages.has(fingerprint))
continue;
seenImages.set(fingerprint, true);
}
const href = `./view?filename=${encodeURIComponent(src.filename)}&type=${
src.type
}&subfolder=${encodeURIComponent(src.subfolder)}&t=${+new Date()}`;
const method = feedDirection.value === "newest first" ? "prepend" : "append";
imageList[method](
$el("div", [
$el(
"a",
{
target: "_blank",
href,
onclick: (e) => {
const imgs = [...imageList.querySelectorAll("img")].map((img) => img.getAttribute("src"));
lightbox.show(imgs, imgs.indexOf(href));
e.preventDefault();
},
},
[$el("img", { src: href })]
),
])
);
if (deduplicateFeed.value) {
// deduplicate by ignoring images with the same filename/type/subfolder
const fingerprint = JSON.stringify({filename: src.filename, type: src.type, subfolder: src.subfolder});
if (seenImages.has(fingerprint)) {
// NOOP: image is a duplicate
} else {
seenImages.set(fingerprint, true);
}
} else {
addImageToFeed(href);
}
}
}
});