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?

  • Rikudou_Sage@lemmings.worldOP
    link
    fedilink
    English
    arrow-up
    20
    ·
    edit-2
    1 year 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.