View difference between Paste ID: mzGd6WD2 and kHPqrnKv
SHOW: | | - or go back to the newest paste.
1
// ==UserScript==
2
// @name         Ylis järjestä vastatuimmat
3
// @version      0.1
4
// @match        https://ylilauta.org/*/*
5
// ==/UserScript==
6
7
(() => {
8
  const $ = document.querySelector.bind(document);
9
  const $$ = (selector) => Array.from(document.querySelectorAll(selector));
10
  const $answers = $$('.answer');
11
  const $buttons = $('.buttons_left');
12
13
  function addButton(text, callback) {
14
    const btn = document.createElement('button');
15
    btn.textContent = text;
16
    btn.onclick = callback;
17
    btn.classList.add('linkbutton');
18
    $buttons.appendChild(btn);
19
  }
20
21
  function getReplyCount(postEl) {
22
      return postEl.querySelectorAll('.replies a').length;
23
  }
24
25
  function handleClick() {
26
      $answers.sort((a, b) => getReplyCount(a) - getReplyCount(b));
27
28
      for (const answer of $answers) {
29
          answer.parentNode.appendChild(answer);
30
      }
31
32
      window.scrollTo(0, document.body.scrollHeight);
33
  }
34
35
  addButton('Näytä vastatuimmat', handleClick);
36
})();