Остання активність 2 days ago

curiouser's Avatar Winston Hoy ревизій цього gist 1 year ago. До ревизії

1 file changed, 2 insertions, 2 deletions

main.js

@@ -9,9 +9,9 @@
9 9 document.querySelector('#virtual-timeline').insertAdjacentHTML('beforebegin', '<div class="flex flex-wrap" id="selects"></div>')
10 10
11 11 const commentCountMap = new Map()
12 - const commentThumbs = Array.from(document.querySelectorAll('#activity-panel img[alt=comment-thumbnail]'))
12 + const commentThumbs = Array.from(document.querySelectorAll('#activity-panel img[alt*=commented]'))
13 13 const likeCountMap = new Map()
14 - const likeThumbs = Array.from(document.querySelectorAll('#activity-panel img[alt=like-thumbnail]'))
14 + const likeThumbs = Array.from(document.querySelectorAll('#activity-panel img[alt*=liked]'))
15 15 const selects = document.querySelector('#selects')
16 16 const srcSet = new Set()
17 17

curiouser's Avatar Winston Hoy ревизій цього gist 2 years ago. До ревизії

1 file changed, 6 insertions, 6 deletions

main.js

@@ -2,18 +2,18 @@
2 2 // this will insert thumbs just above the album photos
3 3
4 4 (() => {
5 + // cleanup and init
6 + try {
7 + document.querySelector('#virtual-timeline').parentNode.removeChild(document.querySelector('#selects'))
8 + } catch {}
9 + document.querySelector('#virtual-timeline').insertAdjacentHTML('beforebegin', '<div class="flex flex-wrap" id="selects"></div>')
10 +
5 11 const commentCountMap = new Map()
6 12 const commentThumbs = Array.from(document.querySelectorAll('#activity-panel img[alt=comment-thumbnail]'))
7 13 const likeCountMap = new Map()
8 14 const likeThumbs = Array.from(document.querySelectorAll('#activity-panel img[alt=like-thumbnail]'))
9 15 const selects = document.querySelector('#selects')
10 16 const srcSet = new Set()
11 -
12 - // cleanup and init
13 - try {
14 - document.querySelector('#virtual-timeline').parentNode.removeChild(document.querySelector('#selects'))
15 - } catch {}
16 - document.querySelector('#virtual-timeline').insertAdjacentHTML('beforebegin', '<div class="flex flex-wrap" id="selects"></div>')
17 17
18 18 // count comments per img
19 19 commentThumbs.forEach(img => {

curiouser's Avatar Winston Hoy ревизій цього gist 2 years ago. До ревизії

1 file changed, 3 insertions, 3 deletions

main.js

@@ -1,5 +1,5 @@
1 - # open the likes/comments activity panel prior to running this in a web console.
2 - # this will insert thumbs just above the album photos
1 + // open the likes/comments activity panel prior to running this in a web console.
2 + // this will insert thumbs just above the album photos
3 3
4 4 (() => {
5 5 const commentCountMap = new Map()
@@ -9,7 +9,7 @@
9 9 const selects = document.querySelector('#selects')
10 10 const srcSet = new Set()
11 11
12 - # cleanup and init
12 + // cleanup and init
13 13 try {
14 14 document.querySelector('#virtual-timeline').parentNode.removeChild(document.querySelector('#selects'))
15 15 } catch {}

curiouser's Avatar Winston Hoy ревизій цього gist 2 years ago. До ревизії

1 file changed, 56 insertions

main.js(файл створено)

@@ -0,0 +1,56 @@
1 + # open the likes/comments activity panel prior to running this in a web console.
2 + # this will insert thumbs just above the album photos
3 +
4 + (() => {
5 + const commentCountMap = new Map()
6 + const commentThumbs = Array.from(document.querySelectorAll('#activity-panel img[alt=comment-thumbnail]'))
7 + const likeCountMap = new Map()
8 + const likeThumbs = Array.from(document.querySelectorAll('#activity-panel img[alt=like-thumbnail]'))
9 + const selects = document.querySelector('#selects')
10 + const srcSet = new Set()
11 +
12 + # cleanup and init
13 + try {
14 + document.querySelector('#virtual-timeline').parentNode.removeChild(document.querySelector('#selects'))
15 + } catch {}
16 + document.querySelector('#virtual-timeline').insertAdjacentHTML('beforebegin', '<div class="flex flex-wrap" id="selects"></div>')
17 +
18 + // count comments per img
19 + commentThumbs.forEach(img => {
20 + const count = commentCountMap.get(img.src) || 0
21 + commentCountMap.set(img.src, count + 1)
22 + srcSet.add(img.src)
23 + })
24 + // count likes per img
25 + likeThumbs.forEach(img => {
26 + const count = likeCountMap.get(img.src) || 0
27 + likeCountMap.set(img.src, count + 1)
28 + srcSet.add(img.src)
29 + })
30 +
31 + // map each img src to a tuple [ src, commentCount, likeCount ]
32 + Array.from(srcSet)
33 + .map(src => [
34 + src,
35 + commentCountMap.get(src) || 0,
36 + likeCountMap.get(src) || 0,
37 + ])
38 + // sort on likes, then comments DESC
39 + .sort((a, b) => {
40 + if (a[2] > b[2]) return -1
41 + else if (a[2] < b[2]) return 1
42 + else {
43 + if (a[1] > b[1]) return -1
44 + else if (a[1] < b[1]) return 1
45 + }
46 + return 0
47 + })
48 + // insert thumb into DOM with counts
49 + .forEach(([ src, comments, likes ]) => {
50 + selects.insertAdjacentHTML('beforeend', `<div style="flex: 0 0 50%;">
51 + <img src="${src}" />
52 + <span>${likes} likes</span>
53 + <span>${comments} comments</span>
54 + </div>`)
55 + })
56 + })()
Новіше Пізніше