4chan Post Sorter

Sorts posts in a 4chan thread by reply count

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name          4chan Post Sorter
// @namespace     4chan-post-sorter
// @description   Sorts posts in a 4chan thread by reply count
// @license       MIT
// @match         http://boards.4chan.org/*/*
// @match         https://boards.4chan.org/*/*
// @grant         GM_registerMenuCommand
// @version       1.0.2
// @author        asdaa
// @icon          https://4chan.org/favicon.ico
// ==/UserScript==

const parent = document.querySelector(".thread");

function getReplies(post) {
    const backlink = post.querySelector(".backlink");
    return backlink ? backlink.querySelectorAll(".quotelink").length : 0;
}

function getSorted(posts) {
   return posts.sort((a, b) => getReplies(b) - getReplies(a));
}

function sortPosts() {
   const posts = [...document.getElementsByClassName("postContainer replyContainer")];
   const sorted = getSorted(posts);
   parent.append(...sorted);
}

var sortBtn = document.createElement('a');
sortBtn.href = 'javascript:;';
sortBtn.innerText = 'Sort';
document.querySelector(".navLinks.desktop").appendChild(sortBtn);
sortBtn.insertAdjacentText('beforebegin', ' [');
sortBtn.insertAdjacentText('afterend', ']');
sortBtn.addEventListener("click", sortPosts, false);

GM_registerMenuCommand('Sort Posts by Reply Count', sortPosts);