Most of the time when people say they have an unpopular opinion, it turns out it's actually pretty popular.

Do you have some that's really unpopular and most likely will get you downvoted?

you are viewing a single comment's thread
view the rest of the comments
[โ€“] 77 points 3 years ago (3 children)

Lemmy needs "sort by controversial" for entertainment purposes.

  • source
  • hideshow 6 child comments
  • [โ€“] [S] 21 points 3 years ago* (last edited 3 years ago)

    Inspired by this, I wrote this quick function to paste in your browser console, if you're on PC:

    (() => {
        const comments = [...document.querySelectorAll('main > div > .comments > li')];
        const commentsHolder = document.querySelector('main > div > .comments');
    
        const sorted = comments.sort((a, b) => {
            const upvotesA = Number(a.querySelector('.comment-bottom-btns > button:nth-child(1) > span').innerText);
            const downvotesA = Number(a.querySelector('.comment-bottom-btns > button:nth-child(2) > span').innerText);
            const upvotesB = Number(b.querySelector('.comment-bottom-btns > button:nth-child(1) > span').innerText);
            const downvotesB = Number(b.querySelector('.comment-bottom-btns > button:nth-child(2) > span').innerText);
    
            const ratioA = upvotesA > downvotesA ? downvotesA / upvotesA : upvotesA / downvotesA;
            const ratioB = upvotesB > downvotesB ? downvotesB / upvotesB : upvotesB / downvotesB;
    
            const diffA = 1 - ratioA;
            const diffB = 1 - ratioB;
    
            if (diffA === diffB) {
                return upvotesA + downvotesA >= upvotesB + downvotesB ? -1 : 1;
            }
    
            return diffA > diffB ? 1 : -1;
        });
        for (const comment of sorted) {
            commentsHolder.appendChild(comment);
        }
    })()
    
    

    It sorts the comments by controversial, but first you need to scroll through all the comments to load them all.

  • source
  • parent