Last active
September 27, 2024 00:43
-
-
Save curiousercreative/a75037c15e891000dac6823c28d3204e to your computer and use it in GitHub Desktop.
Immich shared album selects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// open the likes/comments activity panel prior to running this in a web console. | |
// this will insert thumbs just above the album photos | |
(() => { | |
// cleanup and init | |
try { | |
document.querySelector('#virtual-timeline').parentNode.removeChild(document.querySelector('#selects')) | |
} catch {} | |
document.querySelector('#virtual-timeline').insertAdjacentHTML('beforebegin', '<div class="flex flex-wrap" id="selects"></div>') | |
const commentCountMap = new Map() | |
const commentThumbs = Array.from(document.querySelectorAll('#activity-panel img[alt=comment-thumbnail]')) | |
const likeCountMap = new Map() | |
const likeThumbs = Array.from(document.querySelectorAll('#activity-panel img[alt=like-thumbnail]')) | |
const selects = document.querySelector('#selects') | |
const srcSet = new Set() | |
// count comments per img | |
commentThumbs.forEach(img => { | |
const count = commentCountMap.get(img.src) || 0 | |
commentCountMap.set(img.src, count + 1) | |
srcSet.add(img.src) | |
}) | |
// count likes per img | |
likeThumbs.forEach(img => { | |
const count = likeCountMap.get(img.src) || 0 | |
likeCountMap.set(img.src, count + 1) | |
srcSet.add(img.src) | |
}) | |
// map each img src to a tuple [ src, commentCount, likeCount ] | |
Array.from(srcSet) | |
.map(src => [ | |
src, | |
commentCountMap.get(src) || 0, | |
likeCountMap.get(src) || 0, | |
]) | |
// sort on likes, then comments DESC | |
.sort((a, b) => { | |
if (a[2] > b[2]) return -1 | |
else if (a[2] < b[2]) return 1 | |
else { | |
if (a[1] > b[1]) return -1 | |
else if (a[1] < b[1]) return 1 | |
} | |
return 0 | |
}) | |
// insert thumb into DOM with counts | |
.forEach(([ src, comments, likes ]) => { | |
selects.insertAdjacentHTML('beforeend', `<div style="flex: 0 0 50%;"> | |
<img src="${src}" /> | |
<span>${likes} likes</span> | |
<span>${comments} comments</span> | |
</div>`) | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment