diff options
| Commit | be5deda27a9c141c7f0b4c5bf20522803fe0d3d1 (patch) | |
|---|---|---|
| Author | 2023-03-15 07:52:52 +0000 | |
| Committer | 2023-03-15 07:52:52 +0000 | |
| Files | f6d33b5c3f2098bf91ab38863e56df7d8eadb17b | |
| userscripts-be5deda27a9c141c7f0b4c5bf20522803fe0d3d1.tar userscripts-be5deda27a9c141c7f0b4c5bf20522803fe0d3d1.tar.gz userscripts-be5deda27a9c141c7f0b4c5bf20522803fe0d3d1.zip | ||
| Parent | 2ea8197127d1aa3fe5254e31a3eaa8de1001c553 (diff) | |
[vfk/v1.2] Added a sort elements button to solutions page
1 files changed, 16 insertions, 1 deletions
| -rw-r--r-- | vim-fmi-keystrokes.js | 17 |
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) => { |
