Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Ylis järjestä vastatuimmat
- // @version 0.1
- // @match https://ylilauta.org/*/*
- // ==/UserScript==
- (() => {
- const $ = document.querySelector.bind(document);
- const $$ = (selector) => Array.from(document.querySelectorAll(selector));
- const $answers = $$('.answer');
- const $buttons = $('.buttons_left');
- function addButton(text, callback) {
- const btn = document.createElement('button');
- btn.textContent = text;
- btn.onclick = callback;
- btn.classList.add('linkbutton');
- $buttons.appendChild(btn);
- }
- function getReplyCount(postEl) {
- return postEl.querySelectorAll('.replies a').length;
- }
- function handleClick() {
- $answers.sort((a, b) => getReplyCount(a) - getReplyCount(b));
- for (const answer of $answers) {
- answer.parentNode.appendChild(answer);
- }
- window.scrollTo(0, document.body.scrollHeight);
- }
- addButton('Näytä vastatuimmat', handleClick);
- })();
Advertisement
Add Comment
Please, Sign In to add comment