From be5deda27a9c141c7f0b4c5bf20522803fe0d3d1 Mon Sep 17 00:00:00 2001 From: Kamen Mladenov Date: Wed, 15 Mar 2023 07:52:52 +0000 Subject: [vfk/v1.2] Added a sort elements button to solutions page --- vim-fmi-keystrokes.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/vim-fmi-keystrokes.js b/vim-fmi-keystrokes.js index b76d4bf..7ebafd5 100644 --- a/vim-fmi-keystrokes.js +++ b/vim-fmi-keystrokes.js @@ -18,13 +18,28 @@ if (window.location.pathname.endsWith('solutions')) { document.getElementsByTagName('tbody')[0].childNodes.forEach((x) => { - if (x.tagName != "TR") return; + if (x.tagName != 'TR') return; var countElem = document.createElement('div'); countElem.style.display = 'inline-block'; countElem.style.fontWeight = 'bold'; countElem.innerText = x.children[1].children[0].children.length; x.children[1].insertBefore(countElem, x.children[1].firstChild); }); + + var sortBtn = document.createElement('div'); + sortBtn.classList.add('action'); + sortBtn.innerText = 'Сортирай по решения'; + document.getElementsByClassName('main')[0].children[2].appendChild(sortBtn); + + sortBtn.addEventListener('click', function () { + var rows = [...document.getElementsByClassName('solutions')[0].children[1].children]; + rows.sort(function (a, b) { + var aInt = parseInt(a.children[1].children[0].innerText); + var bInt = parseInt(b.children[1].children[0].innerText); + return aInt > bInt || (aInt == bInt && a.children[2].innerText > b.children[2].innerText); + }); + document.getElementsByClassName('solutions')[0].children[1].replaceChildren(...rows); + }); } else { document.getElementsByTagName('ul')[3].childNodes.forEach((x) => { -- cgit v1.3.1-23-gd82d